Last active
February 19, 2023 04:18
-
-
Save xplato/40ffd990e4d4dea31198013924d6a75b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext, useContext } from "react" | |
import { Children } from "types" | |
interface State {} | |
export const Context = createContext<State>({}) | |
interface Props extends Children {} | |
export const Provider = ({ children }: Props) => { | |
const value: State = {} | |
return <Context.Provider value={value}>{children}</Context.Provider> | |
} | |
export const use = () => { | |
const context = useContext(Context) | |
if (context === undefined) { | |
throw new Error("use must be used within a Provider") | |
} | |
return context | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment