one-hook
Size
0.19 kb
View source

useEventHandler

Stabilize a function's reference across renders. The function is always up to date in effects and DOM events.

Installation

npm install @1hook/use-event-handler

Usage

import {  } from '@1hook/use-event-handler'

Provide a function to useEventHandler:

const  = (.)

onData now has a stable identity, making it safe to use in useEffect.

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

On this page