Skip to content
HooksChapter 22 / 37Advanced4 min read

useEffectEvent

Learn how the React useEffectEvent hook (stable in React 19.2) reads the latest props and state inside an Effect without re-running the Effect.

On this page

1. What is useEffectEvent?

Sometimes part of the logic inside an Effect is reactive (when it changes, the Effect should run again) and part is non-reactive (you only need its latest value, and a change should not restart the Effect).

useEffectEvent separates that non-reactive part from the Effect. It became stable in React 19.2.

2. Why does it matter?

Imagine a chat room component. The connection depends on roomId. When it connects, you show a notification that uses theme.

useEffect onlyWith useEffectEvent
You have to put theme in the depstheme is read inside the Effect Event
Change the theme and the chat reconnectsChange the theme and nothing reconnects
You are tempted to silence the linter warningThe linter is happy, and the deps are exactly right
Fear of stale valuesYou always get the latest theme

3. Where is it used?

SituationReactive partWhat goes in the Effect Event
Chat connectionroomIdA notification that uses theme
Page visit analyticsurlLogging cartCount
Timer or intervalSetting up the intervalA state update using the latest step
Event listenerAttaching the listenerA handler that reads the latest props

4. How does it work?

Separating reactive from non-reactive
The Effect depends only on reactive values
Non-reactive logic goes into useEffectEvent
The Effect calls the Effect Event from the inside
The Effect Event gets the latest props and state on every call
The Effect re-runs only when a reactive value changes

Think of an Effect Event like an event handler, except it fires from inside an Effect instead of from a user click.

5. Code example

Chat room notification

tsx
import { useEffect, useEffectEvent } from "react";
import { createConnection } from "./chat";
import { showNotification } from "./notifications";

export function ChatRoom({ roomId, theme }: { roomId: string; theme: string }) {
  const onConnected = useEffectEvent(() => {
    showNotification("Connected!", theme);
  });

  useEffect(() => {
    const connection = createConnection(roomId);
    connection.on("connected", () => {
      onConnected();
    });
    connection.connect();
    return () => connection.disconnect();
  }, [roomId]);

  return <h1>Room: {roomId}</h1>;
}

Analytics with the latest value

tsx
import { useEffect, useEffectEvent } from "react";
import { logVisit } from "./analytics";

export function Page({ url, cartCount }: { url: string; cartCount: number }) {
  const onVisit = useEffectEvent((visitedUrl: string) => {
    logVisit(visitedUrl, cartCount);
  });

  useEffect(() => {
    onVisit(url);
  }, [url]);

  return <main>{url}</main>;
}

How does the code work?

PartMeaning
useEffectEvent(() => ...)Creates the non-reactive function
Reading theme insideAlways the latest theme, with no dependency
Deps [roomId]Reconnect only when the room changes
onVisit(url)The reactive value is passed as an argument, which makes the intent clear
cartCountIt is only read, so a change does not log again

6. Common mistakes

Mistake: Putting the Effect Event in the dependency array

Why? An Effect Event is non-reactive on purpose, so it does not belong in the deps.

Better: Keep only reactive values in the deps. The latest version of eslint-plugin-react-hooks understands this on its own.

Mistake: Calling an Effect Event from render or an event handler

Why? It is built to be called only from inside Effects, and calling it elsewhere breaks the rules.

Better: For events like clicks, write a normal event handler function.

Mistake: Passing an Effect Event to a child component or another hook

Why? An Effect Event is limited to the Effects of its own component, and passing it around makes behavior unpredictable.

Better: Declare it in the same component whose Effect calls it.

Mistake: Using it to silence every dependency warning

Why? If the logic is truly reactive, moving it into an Effect Event causes a bug, because updates are missed.

Better: Keep only the logic whose changes should not restart the Effect.

7. What to learn before and after

Final quick revision

PointDetail
What it isA function for non-reactive logic inside an Effect
VersionStable in React 19.2
Importimport { useEffectEvent } from "react"
Latest valuesThe latest props and state on every call
DepsAn Effect Event does not go in the deps
Where to call itOnly from inside Effects