merge-refs
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/merge-refs package

    1.0.0 • Public • Published

    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

    Install

    npm i merge-refs

    DownloadsWeekly Downloads

    274,972

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    8.12 kB

    Total Files

    7

    Last publish

    Collaborators

    • wojtekmaj