Files
supabase/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.Context.tsx
Charis cf3ecc93eb chore(docs): turn on strictNullChecks (#36180)
strictNullChecks was off for docs, which lets errors slip through and
leads to incorrect required/optional typing on Zod-inferred types. This
PR enables strictNullChecks and fixes all the existing violations.
2025-06-04 17:05:37 -04:00

40 lines
1.0 KiB
TypeScript

'use client'
import { createContext, useContext } from 'react'
interface ContextProps {
activeRefItem: string | undefined
setActiveRefItem: (x: string) => void
}
interface Provider extends ContextProps {
children?: React.ReactNode
}
// Make sure the shape of the default value passed to
// createContext matches the shape that the consumers expect!
const NavMenuContext = createContext<ContextProps>({
activeRefItem: undefined,
setActiveRefItem: () => {},
})
export const NavigationMenuContextProvider = (props: Provider) => {
const { activeRefItem, setActiveRefItem } = props
const value = {
activeRefItem,
setActiveRefItem,
}
return <NavMenuContext.Provider value={value}>{props.children}</NavMenuContext.Provider>
}
// context helper to avoid using a consumer component
export const useNavigationMenuContext = () => {
const context = useContext(NavMenuContext)
if (context === undefined) {
throw new Error(`useFormContextOnChange must be used within a FormContextProvider.`)
}
return context
}