Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@utilityjs/use-forked-refs

mimshins1.2kMIT1.0.2TypeScript support: included

A React hook for forking/merging multiple refs into a single one.

javascript, typescript, utility, fork refs, merge ref, merge two refs, combine refs

readme

useForkedRefs

A React hook for forking/merging multiple refs into a single one.

license npm latest package npm downloads types

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().