Fix sidebar hydration flash
This commit is contained in:
32
components/providers/sidebar-preference-provider.tsx
Normal file
32
components/providers/sidebar-preference-provider.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { createContext, useContext } from 'react';
|
||||
|
||||
type SidebarPreferenceContextValue = {
|
||||
initialSidebarCollapsed: boolean;
|
||||
};
|
||||
|
||||
const SidebarPreferenceContext =
|
||||
createContext<SidebarPreferenceContextValue>({
|
||||
initialSidebarCollapsed: false
|
||||
});
|
||||
|
||||
type SidebarPreferenceProviderProps = {
|
||||
children: React.ReactNode;
|
||||
initialSidebarCollapsed: boolean;
|
||||
};
|
||||
|
||||
export function SidebarPreferenceProvider({
|
||||
children,
|
||||
initialSidebarCollapsed
|
||||
}: SidebarPreferenceProviderProps) {
|
||||
return (
|
||||
<SidebarPreferenceContext.Provider value={{ initialSidebarCollapsed }}>
|
||||
{children}
|
||||
</SidebarPreferenceContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useSidebarPreference() {
|
||||
return useContext(SidebarPreferenceContext);
|
||||
}
|
||||
Reference in New Issue
Block a user