React useEffectEvent: Separate Event Logic from Effect Dependencies
Read the latest props and state in an Effect callback without reconnecting the external system for unrelated changes.
useEffectEvent creates an Effect Event that can read the latest props and state when called from an Effect. It separates event-like logic from the reactive setup that controls an external subscription or connection.
THE PRODUCTION PROBLEM STATEMENT
An Effect may open a connection based on a room ID and also show a notification using the current theme. Putting both values in the dependency list can reconnect whenever the theme changes, even though the connection itself does not depend on the theme.
Keep reactive setup and event behavior distinct
The Effect remains reactive to values that determine the external system setup. An Effect Event reads current values when the external event fires, so unrelated presentation state does not force the connection to restart.
Effect Events are not dependencies. They may only be called from Effects or other Effect Events, and they must be declared in the same component or custom Hook as the Effect using them.
function ChatRoom({ roomId, theme }: Props) {
const onConnected = useEffectEvent(() => {
showNotification('Connected', theme);
});
useEffect(() => {
const connection = createConnection(roomId);
connection.on('connected', onConnected);
connection.connect();
return () => connection.disconnect();
}, [roomId]);
}Do not use Effect Events to silence the linter
If a value changes which resource the Effect should connect to, it belongs in the dependency array. Moving that value behind an Effect Event hides a real reactive dependency and can leave the component subscribed to the wrong resource.
Use the latest-hooks lint plugin that understands Effect Events. Keep the code clear about which values should restart the Effect and which values are read only when an event occurs.
Use the hook only for effects that represent external systems
A user click handler is an ordinary event handler and should use the values from the render that created it. Effect Events are for callbacks invoked as part of an Effect-managed external system, such as a connection, timer, or browser listener.
The hook is available in React 19.2. It does not replace cleanup, state modeling, or a correct dependency list.
Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
No. React documents Effect Events as non-reactive functions that should not be listed as dependencies.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Understanding React 18 Concurrency: useTransition, useDeferredValue, and Suspense Architecture
A deep architectural dive into cooperative scheduling, non-blocking state updates, fiber priority levels, and avoiding UI tearing in production React applications.
React Memoization Pitfalls: When useMemo and useCallback Actually Hurt Performance
A pragmatic examination of shallow comparison overhead, closure retention, cache churn, and why premature memoization degrades React application speed.