easy ref merge is a react/react-native package that helps you to merge more than one reference and inject them into the same component.
#npm
npm install easy-ref-merge
#yarn
yarn add easy-ref-merge
We have only one function
- refsMerge its called with any number of references and produce single merged reference.
import refsMerge from "easy-ref-merge";
./OuterWrapper.js
import InnerWrapper from "./InnerWrapper.js";
import React, { useRef } from "react";
const OuterWrapper = () => {
const ref = useRef();
return <InnerWrapper ref={ref} />;
};
./InnerWrapper.js
import React from "react";
import { Text } from "react-native";
import refsMerge from "easy-ref-merge";
const InnerWrapper = React.forwardRef((props, ref) => {
const localRef = useRef(/*a reference generated for special purpose*/);
return <Text ref={refsMerge(localRef, ref)}>Easy Ref Merge</Text>;
}, []);
- ✔️ small size package 💪
- ✔️ easy to use 💪
- ✔️ allows you to merge any number of references 💪