@react-hook/merged-ref
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

useMergedRef()

Bundlephobia Types Build status NPM Version MIT License

npm i @react-hook/merged-ref

A React hook for merging multiple refs into one ref

Quick Start

import React from 'react'
import useMergedRef from '@react-hook/merged-ref'

const Component = React.forwardRef((props, ref) => {
  const otherRef = React.useRef(null)
  const multiRef = useMergedRef(ref, otherRef)
  return <div ref={multiRef} />
})

API

useMergedRef(...refs)

function useMergedRef<T>(...refs: React.Ref<T>[]): React.RefCallback<T>
Argument Description
refs React callback refs or refs created with useRef(), createRef()

Returns React.RefCallback

Returns a callback ref

LICENSE

MIT

/@react-hook/merged-ref/

    Package Sidebar

    Install

    npm i @react-hook/merged-ref

    Weekly Downloads

    34,515

    Version

    1.3.2

    License

    MIT

    Unpacked Size

    16.3 kB

    Total Files

    26

    Last publish

    Collaborators

    • jaredlunde