A function that merges React refs into one.
npm install merge-refs !downloads 
A function that merges React refs into one. Filters out invalid (eg. falsy) refs as well and returns original ref if only one valid ref was given.
- Install by executing npm install merge-refs or yarn add merge-refs.
- Import by adding import mergeRefs from 'merge-refs'.
- Use it in ref like so:
- Refs created using createRef()
- Refs created using useRef()
- Functional refs
``tsx
function Hello() {
const ref1 = useRef
const ref2 = (element: HTMLDivElement) => {
// I'm going to be called!
};
return
;The MIT License.
Wojciech Maj |