react-merge-refs
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

react-merge-refs

License npm package npm bundle size CI

React utility to merge refs 🖇

npm install react-merge-refs

Example

import React from "react";
import { mergeRefs } from "react-merge-refs";

const Example = React.forwardRef(function Example(props, ref) {
  const localRef = React.useRef();
  return <div ref={mergeRefs([localRef, ref])} />;
});

Why?

When developing low level UI components, it is common to have to use a local ref but also support an external one using React.forwardRef. Natively, React does not offer a way to set two refs inside the ref property. This is the goal of this small utility.

Today a ref can be a function or an object, tomorrow it could be another thing, who knows. This utility handles compatibility for you.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.1
    134,985
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.1.1
    134,985
  • 2.1.0
    1
  • 2.0.2
    54,344
  • 2.0.1
    12,492
  • 2.0.0
    71
  • 1.1.0
    733,593
  • 1.0.0
    4,443

Package Sidebar

Install

npm i react-merge-refs

Weekly Downloads

939,929

Version

2.1.1

License

MIT

Unpacked Size

5.26 kB

Total Files

6

Last publish

Collaborators

  • neoziro