one-hook
Size
0.15 kb
View source

useLatestRef

Transform anything into a ref. The ref is always up to date in effects and DOM events.

Installation

npm install @1hook/use-latest-ref

Usage

import {  } from '@1hook/use-latest-ref'

Transform any value into a ref:

const  = ()

Use ref.current to read the latest value in effects, changes to value do not trigger the effect.

(() => {
  // only runs once
  .('value', .)
}, [])

On this page