createRef<T> function

Ref<T?> createRef<T>()

Creates a Ref object that can be attached to a ReactElement via the ref prop.

Example:

class FooComponent extends react.Component2 {
  final Ref<BarComponent> barRef = createRef();
  final Ref<InputElement> inputRef = createRef();

  render() => react.div({}, [
    Bar({'ref': barRef}),
    react.input({'ref': inputRef}),
  ]);
}

Learn more: reactjs.org/docs/refs-and-the-dom.html#creating-refs.

Implementation

// This return type must always be nullable since the ref is always initially empty,
// and in most usages represents a component ref object which could be null.
// useRef2 on the other hand, can be made non-nullable.
Ref<T?> createRef<T>() => Ref<T?>.fromJs(React.createRef());