项目
在 GitHub 查看
gregberge/react-merge-refs
关于
用于合并 refs 的 React 工具 🖇
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文react-merge-refs
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
探索相关项目
加载中…