Provider property

UiFactory<ProviderProps<TValue>> Provider
final

Every Context object comes with a Provider component that allows consuming components to subscribe to context changes.

Accepts a value prop to be passed to consuming components that are descendants of this Provider.

All consumers that are descendants of a Provider will re-render whenever the Provider’s value prop changes. The propagation from Provider to its descendant consumers is not subject to the shouldComponentUpdate method, so the consumer is updated even when an ancestor component bails out of the update.

Example:

Context MyContext = createContext();
...
class MyComponent extends UiComponent2<...> {
  render() {
    return (MyContext.Provider()..value = 'new context value')(
      MyContext.Consumer()(
        (value) {
          return Dom.span()(
            '$value', // Outputs: 'new context value'
          );
        }
      );
    );
  }
}

Learn More: react.dev/reference/react/createContext#provider

Implementation

final UiFactory<ProviderProps<TValue>> Provider;