Package Exports
- merge-refs
- merge-refs/dist/cjs/index.js
- merge-refs/dist/esm/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (merge-refs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Merge-Refs
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.
tl;dr
- Install by executing
npm install merge-refs
oryarn add merge-refs
. - Import by adding
import mergeRefs from 'merge-refs'
. - Use it in
ref
like so:<div ref={mergeRefs(ref, someOtherRef)} />
Accepted refs
- Refs created using
React.createRef()
- Refs created using
React.useRef()
- Functional refs
Example
function Hello() {
const ref1 = useRef(); // I'm going to be updated!
const ref2 = (element) => {
// I'm going to be called!
};
return <div ref={mergeRefs(ref1, ref2)} />;
}
License
The MIT License.
Author
![]() |
Wojciech Maj kontakt@wojtekmaj.pl https://wojtekmaj.pl |