Need help with react-merge-refs?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

gregberge
247 Stars 9 Forks MIT License 15 Commits 1 Opened issues

Description

React utility to merge refs đź–‡

Services available

!
?

Need anything else?

Contributors list

# 4,007
JavaScr...
gatsbyj...
inline-...
webpack...
10 commits
# 5,355
TypeScr...
react-c...
reactjs
Mongoos...
1 commit

react-merge-refs

Node.js 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

; });

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.