mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
cf3ecc93eb
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.
40 lines
1.0 KiB
TypeScript
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
|
|
}
|