feat: 修改代码结构
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user