feat: 修改代码结构

This commit is contained in:
2025-08-14 22:34:44 -07:00
parent f9de5fcb4f
commit 77e246198f
4 changed files with 22 additions and 4 deletions
+8 -2
View File
@@ -52,8 +52,14 @@ const SidebarContext = React.createContext<SidebarContext>(SAFE_SIDEBAR_CONTEXT)
function useSidebar() {
const context = React.useContext(SidebarContext);
// Optionally warn in development when using the safe fallback
if (process.env.NODE_ENV !== 'production' && context === SAFE_SIDEBAR_CONTEXT) {
console.warn('useSidebar is used outside of a SidebarProvider. Falling back to no-op context.');
if (!context) {
return {
toggleSidebar: () => {
console.warn(
'useSidebar is used outside of a SidebarProvider. Falling back to no-op context.',
);
},
}; // 提供默認空函數,防止首頁報錯
}
return context;
}