A hook for merging multiple refs into a single stable callback ref.
Made by raouf.codesOverview
The useMergeRefs hook combines multiple refs into one callback ref. It is useful when a component needs to forward a ref while also keeping an internal ref for measurements, focus handling, or animations.
Logic Lifecycle
- Input collection — Accepts a spread of refs (object refs, callback refs, or
null) - Callback creation — Returns a single callback ref that assigns to all valid refs
- Assignment — When the element mounts/unmounts, updates all refs synchronously
Installation
Usage
Basic
Merging Callback and Object Refs
API Reference
useMergeRefs
| Prop | Type | Default |
|---|---|---|
refs | (React.Ref<T> | undefined | null)[] | - |
returns? | React.RefCallback<T> | - |
Features
- Multi-ref support — Merge object refs and callback refs in one place.
- Stable callback — Returns a memoized callback suitable for React refs.
- React 19 compatible — Works with current ref patterns and callback cleanup behavior.
Built by raouf.codes. The source code is available on GitHub.
Last updated: 3/21/2026