1.0.0 • Published 25 days ago

@rabiepenpm/incidunt-repudiandae-exercitationem v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
25 days ago

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 @rabiepenpm/incidunt-repudiandae-exercitationem or yarn add @rabiepenpm/incidunt-repudiandae-exercitationem.
  • Import by adding import mergeRefs from '@rabiepenpm/incidunt-repudiandae-exercitationem'.
  • 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