useMergeRefs
Combines multiple React refs (callback refs, RefObjects, or null/undefined) into a single stable callback ref with React 19 cleanup support.
Loading preview...
The useMergeRefs hook merges any number of RefObjects and callback refs into a single memoized callback ref, forwarding React 19 ref cleanup functions when the element unmounts.
Installation
Usage
Examples
Combining a Local Ref with a Forwarded Prop Ref
Merge an internal useRef with a consumer-supplied ref prop so both references point to the same underlying DOM node.
Combining Multiple Hook Refs
Attach multiple ref-based hooks (such as useMeasure and useFocus) to the same element.