Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

React utility to merge refs 🖇

License

NotificationsYou must be signed in to change notification settings

gregberge/react-merge-refs

Repository files navigation

Licensenpm packagenpm bundle sizeCI

React utility to merge refs 🖇

npm install react-merge-refs

Example

importReactfrom"react";import{mergeRefs}from"react-merge-refs";constExample=React.forwardRef(functionExample(props,ref){constlocalRef=React.useRef();return<divref={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 usingReact.forwardRef. Natively, React does not offer a way to set two refs inside theref property. This is the goal of this small utility.

Today aref can be afunction or anobject, tomorrow it could be another thing, who knows. This utility handles compatibility for you.

License

MIT

About

React utility to merge refs 🖇

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors9


[8]ページ先頭

©2009-2025 Movatter.jp