1- import { useAtom , useSetAtom } from 'jotai' ;
1+ import { useSetAtom } from 'jotai' ;
22import type { ReactNode } from 'react' ;
33import { useId , useRef } from 'react' ;
44import CrossSvg from '../assets/cross.svg' ;
@@ -13,16 +13,15 @@ import {
1313import { SearchableExampleList } from './SearchableExampleList.tsx' ;
1414import { Button } from './design/Button.tsx' ;
1515import { Toggle } from './design/Toggle.tsx' ;
16- import { useHydrated } from '../utils/useHydrated.ts' ;
16+ import { useHydratedAtom } from '../utils/useHydrated.ts' ;
1717
1818interface ExampleLayoutProps {
1919 children ?: ReactNode | undefined ;
2020}
2121
2222export function ExampleLayout ( props : ExampleLayoutProps ) {
23- const [ menuShown , setMenuShown ] = useAtom ( menuShownAtom ) ;
24- const [ codeShown , setCodeShown ] = useAtom ( codeEditorShownAtom ) ;
25- const hydrated = useHydrated ( ) ;
23+ const [ menuShown , setMenuShown ] = useHydratedAtom ( menuShownAtom , false ) ;
24+ const [ codeShown , setCodeShown ] = useHydratedAtom ( codeEditorShownAtom , false ) ;
2625
2726 return (
2827 < >
@@ -35,7 +34,7 @@ export function ExampleLayout(props: ExampleLayoutProps) {
3534
3635 < Button onClick = { ( ) => setCodeShown ( ( prev ) => ! prev ) } >
3736 { /* Applying the actual label only after the component has been hydrated */ }
38- { codeShown && hydrated ? 'Preview' : 'Code' }
37+ { codeShown ? 'Preview' : 'Code' }
3938 </ Button >
4039 </ div >
4140
@@ -49,8 +48,9 @@ export function ExampleLayout(props: ExampleLayoutProps) {
4948
5049function SideMenu ( ) {
5150 const setMenuShown = useSetAtom ( menuShownAtom ) ;
52- const [ experimentalShowing , setExperimentalShowing ] = useAtom (
51+ const [ experimentalShowing , setExperimentalShowing ] = useHydratedAtom (
5352 experimentalExamplesShownAtom ,
53+ true ,
5454 ) ;
5555 const scrollRef = useRef < HTMLDivElement > ( null ) ;
5656 const experimentalExamplesToggleId = useId ( ) ;
0 commit comments