@landmineaknpm/sequi-alias-sapiente

1.0.0 • Public • Published

npm downloads CI

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 @landmineaknpm/sequi-alias-sapiente or yarn add @landmineaknpm/sequi-alias-sapiente.
  • Import by adding import mergeRefs from '@landmineaknpm/sequi-alias-sapiente'.
  • Use it in ref like so: <div ref={mergeRefs(ref, someOtherRef)} />

Accepted refs

  • Refs created using createRef()
  • Refs created using useRef()
  • Functional refs

Example

function Hello() {
  const ref1 = useRef<HTMLDivElement>(); // I'm going to be updated!
  const ref2 = (element: HTMLDivElement) => {
    // I'm going to be called!
  };

  return <div ref={mergeRefs(ref1, ref2)} />;
}

License

The MIT License.

Author

Wojciech Maj Wojciech Maj

Readme

Keywords

Package Sidebar

Install

npm i @landmineaknpm/sequi-alias-sapiente

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

14.1 kB

Total Files

10

Last publish

Collaborators

  • hai836799