You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
343 B
12 lines
343 B
|
3 years ago
|
import { useContext } from 'react';
|
||
|
|
import type { Context as ContextType } from 'react';
|
||
|
|
import { invariant } from '../invariant';
|
||
|
|
|
||
|
|
export default function useRequiredContext<T>(
|
||
|
|
Context: ContextType<T | null>,
|
||
|
|
): T {
|
||
|
|
const result: T | null = useContext(Context);
|
||
|
|
invariant(result, 'Could not find required context');
|
||
|
|
return result;
|
||
|
|
}
|