useRef<T> function

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

A box of initialValue, the same one in every build: what is put in it stays without rebuilding anything.

How many times the widget was built, which no build shows:

HookBuilder(
  builder: (context) {
    final builds = useRef(0);
    builds.value++;
    return const Text('Ready');
  },
)

Implementation

ObjectRef<T> useRef<T>(T initialValue) => use(
  _MemoizedHook(() => ObjectRef(initialValue), const [], 'useRef<$T>'),
);