Stop Rebuilding UI

Shadcn.io is not affiliated with official shadcn/ui

React useEventCallback Hook

React useEventCallback hook for stable callback references with fresh state access. No stale closures, no re-renders. TypeScript ready.

Stop fighting stale closures in React. useEventCallback returns a stable function reference that always accesses the latest props and state. Pass it to child components or useEffect dependencies without causing re-renders. Uses useLayoutEffect internally to update the ref synchronously. Prevents the "callback sees old state" bug that plagues setTimeout, event listeners, and memoized children. Full TypeScript generics support. Perfect for event handlers in optimized components, custom hooks, or anywhere you need stable identity with fresh values. Works with Next.js App Router.

React useEventCallback Hook preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.