Untitled
unknown
typescript
a year ago
432 B
10
Indexable
/* Creates react context provider, and a hook consumer for given hook template */
export function makeContext<T>(useValue: () => T): readonly [FC<PropsWithChildren>, () => T] {
const Context = createContext<T>({} as T)
const provider: FC<PropsWithChildren> = ({ ...props }) => (
<Context.Provider value={useValue()} {...props} />
)
const consumer = () => useContext(Context)
return [provider, consumer]
}Editor is loading...
Leave a Comment