Skip to content

Instantly share code, notes, and snippets.

@xplato
Last active February 19, 2023 04:18
Show Gist options
  • Save xplato/40ffd990e4d4dea31198013924d6a75b to your computer and use it in GitHub Desktop.
Save xplato/40ffd990e4d4dea31198013924d6a75b to your computer and use it in GitHub Desktop.
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