@utilityjs/use-forked-refs
v1.0.2
Published
A React hook for forking/merging multiple refs into a single one.
Downloads
7
Maintainers
Readme
A React hook for forking/merging multiple refs into a single one.
npm i @utilityjs/use-forked-refs | yarn add @utilityjs/use-forked-refs
Usage
import * as React from "react";
import useForkedRefs from "@utilityjs/use-forked-refs";
const MyComponent = React.forwardRef((props, ref) => {
const rootRef = React.useRef(null);
const handleRef = useForkedRefs(ref, rootRef);
return <div ref={handleRef} />;
});
API
useForkedRefs(...refs)
declare const useForkedRefs: <T>(...refs: React.Ref<T>[]) => (instance: T | null) => void;
refs
React callback refs or refs created with useRef()
or createRef()
.