mergeRefs
Merges multiple React refs into a single ref.
Installation
npm install @madeinhaus/utils
Import
import { mergeRefs } from '@madeinhaus/utils';
Parameters
...refs
(Ref[]): The React refs to merge.
Returns
- (Ref): A single React ref that merges all the input refs.
Usage
import { useRef } from 'react';
import { mergeRefs } from '@madeinhaus/utils';
function MyComponent() {
const ref1 = useRef(null);
const ref2 = useRef(null);
const mergedRef = mergeRefs(ref1, ref2);
return <div ref={mergedRef}>Hello, world!</div>;
}
In this example, we import the mergeRefs
function from the @madeinhaus/utils
package and use it to merge two React refs into a single ref.