1.0.2 • Published 2 years ago

@utilityjs/use-forked-refs v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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