useRef<T> function

UseRefHook<T> useRef<T>(
  1. T initialValue
)

useRef returns a mutable ref object whose .value property is initialized to the passed argument initialValue.

The returned object will persist for the full lifetime of the scope.

Implementation

UseRefHook<T> useRef<T>(T initialValue) {
  var useRefHook = useHook();
  useRefHook ??= setupHook(UseRefHook._(initialValue));

  if (useRefHook is! UseRefHook<T>) {
    throw Exception(
      'Expecting hook of type: $UseRefHook '
      'but got: ${useRefHook.runtimeType}. '
      'Please make sure your hooks call order is not dynamic.',
    );
  }

  return useRefHook;
}