useRefInit<T> function

Ref<T> useRefInit<T>(
  1. T initialValue
)

Returns a mutable Ref object with Ref.current property initialized to initialValue.

Changes to the Ref.current property do not cause the containing uiFunction component to re-render.

The returned Ref object will persist for the full lifetime of the uiFunction component. Compare to createRef which returns a new Ref object on each render.

Note: there are two rules for using Hooks:

  • Only call Hooks at the top level.
  • Only call Hooks from inside the first argument of uiFunction.

Example:

UiFactory<UseRefExampleProps> UseRefExample = uiFunction(
  (props) {
    final countRef = useRefInit(0);

    handleClick([_]) {
      ref.current = ref.current + 1;
      window.alert('You clicked ${ref.current} times!');
    }

    return Fragment()(
      (Dom.button()..onClick = handleClick)('Click me!'),
    );
  },
  _$UseRefExampleConfig, // ignore: undefined_identifier
);

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

Implementation

Ref<T> useRefInit<T>(T initialValue) => react_hooks.useRefInit(initialValue);