useForkRef
Merges multiple refs into a single callback ref.
Merges multiple React refs (callback refs, ref objects, or null) into a single callback ref. Useful when a component needs to forward its ref while also keeping an internal reference.
Import#
import { useForkRef } from '@volue/wave-react';
Example#
const Component = React.forwardRef((props, forwardedRef) => {const internalRef = React.useRef(null);const composedRef = useForkRef(forwardedRef, internalRef);return <div ref={composedRef} {...props} />;});
API Reference#
Arguments#
Prop | Type | Default |
|---|---|---|
...refs | (Ref<T> | undefined | null)[] | — |
Returns#
(instance: T | null) => void — A callback ref that forwards the instance to all provided refs.