useLazyRef

Creates a ref whose initial value is lazily computed on first render.

Creates a ref whose initial value is lazily computed by a factory function on first render. Unlike useRef, the initializer function is only called once, avoiding unnecessary computation on re-renders.

Import#

import { useLazyRef } from '@volue/wave-react';

Example#

Refs in following example simulate expensive computation by creating a large Map. useLazyRef skips computation cost after the first render.


API Reference#

Arguments#

Prop
Type
Default
getValue*
() => T

Returns#

RefObject<T>