contextType property

  1. @override
Context? contextType
override

The contextType property lets you consume the nearest current value of that context's Provider using context.

contextType is assigned as Context.reactDartContext after being created by createContext.

Example:

Context MyContext = createContext('test');

class MyClass extends UiComponent2 {
  @override
  final contextType = MyContext.reactDartContext;

  render() {
    return Dom.span()(
      '${this.context}', // Outputs: 'test'
   );
  }
}

See: reactjs.org/docs/context.html#classcontexttype

Implementation

@override
react.Context? get contextType => super.contextType;