Skip to Content
react-utilscreateRequiredContext

createRequiredContext

See source on Github

Create a useContext hook where its returned value will always be its intended type. Using the hook outside of its provider tree will result in an error being thrown.

Example

const [useFoo, FooProvider] = createRequiredContext<FooContextValue>('Foo') const [useBaz, BazProvider, BazConsumer] = createRequiredContext<BazContextValue>('Baz')