composeRefs
A utility that composes multiple React refs (callback refs and RefObjects) into a single callback ref. Useful when you need to assign a DOM node to more than one ref at the same time.
For the React hook version that wraps this in useCallback for stability, see useComposedRefs in @ngrok/mantle/hooks.
Usage
Forwarding a ref while keeping an internal ref
The most common use case: accept a ref prop from the parent while keeping an internal ref for the component itself.
With multiple refs
With callback refs
composeRefs accepts any mix of RefObjects and callback refs:
API
Accepts any number of refs (callback refs, RefObjects, or undefined). Returns a single callback ref that, when called with a node, assigns the node to every given ref. undefined refs are safely skipped. When a callback ref returns a React 19 ref cleanup function, the composed ref propagates it, so each cleanup runs on unmount.