@usefy/use-event-callback
v0.25.1
Published
A React hook returning a stable callback that always sees the latest props and state
Maintainers
Readme
Overview
useEventCallback is part of the @usefy ecosystem — a collection of production-ready, TypeScript-first, SSR-safe React hooks. A stable callback that always sees the latest props and state.
Features
- Stable identity — pass to effects/listeners without re-subscribing
- Always fresh — reads the latest props and state when called
useEffectEvent-style — the community equivalent- TypeScript-first — full type inference and exported types
- Tiny & tree-shakeable — zero dependencies, published as its own package
Installation
# npm
npm install @usefy/use-event-callback
# yarn
yarn add @usefy/use-event-callback
# pnpm
pnpm add @usefy/use-event-callbackRequires React 18 or 19 (peerDependencies: "react": "^18.0.0 || ^19.0.0").
Quick Start
import { useEventCallback } from "@usefy/use-event-callback";
const onClick = useEventCallback(() => console.log(count));
// stable identity, always reads the current countAPI
useEventCallback<Args, R>(fn): (...args) => R — a referentially-stable function that proxies to the latest fn.
Testing
📊 View Detailed Coverage Report (GitHub Pages) — 5 tests, 100% statement coverage.
License
MIT © mirunamu
This package is part of the usefy monorepo.
