Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@stackmeister/react-use-reinitialized-refs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stackmeister/react-use-reinitialized-refs

@stackmeister/react-use-merged-ref ======================================

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

@stackmeister/react-use-merged-ref

Got multiple refs from hooks or own useRef calls, but you can only pass one to an element?

This library can merge multiple refs of the same type into one.

Usage

Basic Usage

import useMergedRef from '@stackmeister/react-use-merged-ref'

const App = () => {
  const scrollingRef = useScrolling()
  const { ref: touchRef } = useTouchControls()
  const { calc, ref: calcRef } = useCalc()
  const ref = useMergedRef(scrollingRef, touchRef, calcRef)

  return (
    <div ref={ref}>
      Hello World!
    </div>
  )
}

Easy to encapsulate

import useMergedRef from '@stackmeister/react-use-merged-ref'

const useAppThings = () => {
  const scrollingRef = useScrolling()
  const { ref: touchRef } = useTouchControls()
  const { calc, ref: calcRef } = useCalc()

  return {
    calc,
    ref: useMergedRef(scrollingRef, touchRef, calcRef)
  }
}

const App = () => {
  const { calc, ref } = useAppThings()

  return (
    <div ref={ref}>
      Hello World!
    </div>
  )
}

FAQs

Package last updated on 09 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts