@utilityjs/use-forked-refs
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i @utilityjs/use-forked-refs

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

4.84 kB

Total Files

8

Last publish

Collaborators

  • mimshins