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.

  • @param contextName - Base name used for the context display name and errors.
  • @returns The required hook, provider, and consumer.

Example

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