useContext<T> function

T useContext<T>(
  1. Context<T> context
)

Returns the value of the nearest Context.Provider for the provided context object every time that context is updated.

The usage is similar to that of a Context.Consumer in that the return type of useContext is dependent upon the typing of the value passed into createContext and Context.Provider.

Note: there are two rules for using Hooks:

Example:

Context countContext = createContext(0);

UseCallbackTestComponent(Map props) {
  final count = useContext(countContext);

  return react.div({}, [
    react.div({}, ['The count from context is $count']), // initially renders: 'The count from context is 0'
  ]);
}

Learn more: reactjs.org/docs/hooks-reference.html#usecontext.

Implementation

T useContext<T>(Context<T> context) => ContextHelpers.unjsifyNewContext(React.useContext(context.jsThis)) as T;