Files
supabase/apps/docs/hooks/useMenuState.ts
Charis 7cf2eae953 fix: statically build the right nav on each page (#21469)
Before: All pages have the Home nav menu in static HTML, which is blown away and replaced by the proper nav menu upon hydration. This leads to jankiness when the page first loads and an unpleasant flash of the wrong nav menu (especially obvious on the JavaScript ref page, which takes a long time to process and rerender the nav).

Now: All pages have their correct nav menu in static HTML.
2024-02-23 11:38:06 -05:00

23 lines
499 B
TypeScript

import { proxy, useSnapshot } from 'valtio'
export const menuState = proxy({
// values
menuActiveRefId: 'home',
// set states
setMenuActiveRefId: (value) => {
menuState.menuActiveRefId = value
},
menuMobileOpen: false,
setMenuMobileOpen: (value) => {
menuState.menuMobileOpen = value
},
})
export const useMenuActiveRefId = () => {
return useSnapshot(menuState).menuActiveRefId
}
export const useMenuMobileOpen = () => {
return useSnapshot(menuState).menuMobileOpen
}