useMergeRefs
Returns a function that receives the element and assign the value to the given React refs.
API
function useMergeRefs<Generic = HTMLElement>(firstRef: SingleRef<Generic>, secondRef: SingleRef<Generic>): MergedRefCallback<Generic>;
Usage
import { useMergeRefs } from '@jtmdias/js-utilities';
// a div with multiple refs
function Example({ ref, ...props }) {
const internalRef = React.useRef();
const refs = useMergeRefs(internalRef, ref);
return (
<div {...props} ref={refs}>
A div with multiple refs.
</div>
);
}