JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1433189
  • Score
    100M100P100Q196446F
  • License MIT

A function that merges React refs into one.

Package Exports

  • merge-refs

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

npm downloads build dependencies dev dependencies tested with jest

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 or yarn add merge-refs.
  • Import by adding import mergeRefs from 'merge-refs'.
  • Pass arguments to it. Forget.

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
http://wojtekmaj.pl