Sub topic 14
From experimental_useEffectEvent to the Stable API
This chapter assumes you already know how to declare an Effect Event, what rules it follows, and how the exhaustive-deps lint rule treats it. It covers one practical question: which React version you need, and what changes when you move from the experimental API to the stable one.
The hook has had three names. Code written against older versions still exists in real projects, in blog posts, and in older Stack Overflow answers, so it helps to recognize all three.
A short history
The idea first appeared in 2022 as a public RFC (a "request for comments" design proposal) for a hook called useEvent. That proposal tried to cover two cases: event handlers passed to child components, and non-reactive logic inside Effects. The React team narrowed the scope to the second case and renamed the hook useEffectEvent. The new name says where the function is meant to be called.
During the experimental period, the hook shipped only in React's experimental release channel under the name experimental_useEffectEvent. React 19.2, released in October 2025, made it stable as useEffectEvent. The same release cycle updated eslint-plugin-react-hooks so the dependency linter recognizes the stable name.
| Name | Where it lived | Status today |
|---|---|---|
| `useEvent` | RFC only, never shipped in a stable release | Abandoned proposal |
| `experimental_useEffectEvent` | `react@experimental` builds | Superseded, do not use in new code |
| `useEffectEvent` | `react` 19.2 and later | Stable |
Checking what your project has
Before you write import { useEffectEvent } from 'react', confirm the installed version. With an older React, the import gives you undefined, and the first call fails with "useEffectEvent is not a function". Depending on your bundler, you may get no warning at build time.
npm ls react react-dom eslint-plugin-react-hooksYou can also check at runtime, which is handy in a shared component library that might run inside several host apps:
import { version } from 'react';
console.log(version); // for example "19.2.0"To upgrade, install React, React DOM, and the hooks lint plugin together so their versions match:
npm install react@^19.2.0 react-dom@^19.2.0
npm install --save-dev eslint-plugin-react-hooks@latestIf you use TypeScript, upgrade @types/react too. Older type packages do not declare useEffectEvent, so the compiler reports a missing export even when the runtime has it.
npm install --save-dev @types/react@^19.2.0 @types/react-dom@^19.2.0Migrating from the experimental name
The stable hook behaves the same way as the experimental one for everything this tutorial covers. Migrating mostly means changing the import. Here is a component written against the experimental build:
import { useEffect, experimental_useEffectEvent as useEffectEvent } from 'react';
import { createConnection } from './chat.js';
import { showNotification } from './notifications.js';
function ChatRoom({ roomId, theme }) {
const onConnected = useEffectEvent(() => {
showNotification('Connected!', theme);
});
useEffect(() => {
const connection = createConnection(roomId);
connection.on('connected', () => {
onConnected();
});
connection.connect();
return () => connection.disconnect();
}, [roomId]);
}Many teams aliased the import like this so that the rest of the file already used the final name. If your code does the same, the migration is a single line:
import { useEffect, useEffectEvent } from 'react';If the code called experimental_useEffectEvent(...) directly with no alias, change both the import and every call site. A project-wide search for experimental_useEffectEvent finds them all. After the change, nothing in the codebase should import from react@experimental for this hook. Experimental builds can change without notice and should not run in production.
Making the linter understand the stable name
Earlier chapters described how the exhaustive-deps rule leaves Effect Events out of the dependencies it asks for, and reports an error if you list one. The rule can only do this if it recognizes the hook. Older plugin versions recognized only the experimental name. With an old plugin and the stable import, the linter treats onConnected as an ordinary function declared in the component. It then asks you to add it to the dependency array, which is exactly the mistake Effect Events exist to prevent.
This is the most common failure after an upgrade. If the linter suddenly tells you to add an Effect Event to a dependency array, check the plugin version before you change any code.
A minimal flat config that turns on both hooks rules looks like this:
// eslint.config.js
import reactHooks from 'eslint-plugin-react-hooks';
export default [
{
files: ['**/*.{js,jsx}'],
languageOptions: {
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
plugins: { 'react-hooks': reactHooks },
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
},
},
];With a current plugin, rules-of-hooks also reports misuse covered in the rules chapter, such as calling an Effect Event outside an Effect or passing it to a child component.
Common upgrade errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `useEffectEvent is not a function` at runtime | React older than 19.2 is installed, or two copies of React are bundled | Upgrade `react` and `react-dom` together; run `npm ls react` to find duplicates |
| TypeScript: module has no exported member `useEffectEvent` | Old `@types/react` | Upgrade `@types/react` to match React |
| Linter asks you to add the Effect Event to dependencies | Old `eslint-plugin-react-hooks` | Upgrade the plugin |
| Code still imports `experimental_useEffectEvent` | Migration was incomplete | Search the codebase and switch to the stable import |
| A library breaks in host apps on React 18 | The library imports a hook its peers may not have | Raise the library's `react` peer dependency range to `>=19.2.0`, or use a fallback |
The last row matters for library authors. If your package declares "react": "^18.0.0 || ^19.0.0" as a peer dependency and imports useEffectEvent, apps on React 18 or on 19.0 and 19.1 will crash. Either narrow the peer range or keep supporting older versions with a fallback.
Fallback for projects that cannot upgrade yet
Some projects are stuck on React 18 for a while. Before the stable hook existed, a common workaround stored the latest callback in a ref and returned a wrapper that reads from it:
import { useRef, useInsertionEffect, useCallback } from 'react';
export function useEffectEventFallback(fn) {
const ref = useRef(fn);
useInsertionEffect(() => {
ref.current = fn;
}, [fn]);
return useCallback((...args) => {
return ref.current(...args);
}, []);
}useInsertionEffect runs before any layout or regular Effects. By the time your Effects call the wrapper, ref.current already holds the function from the latest render. That matches the "always sees the latest props and state" behavior you learned earlier.
The fallback differs from the real hook in ways that matter:
- It does not throw if you call it during rendering. The real hook does, which catches bugs earlier.
- The returned function has a stable identity. The linter does not recognize the custom hook, so it will ask you to list the wrapper as a dependency. Listing it is harmless because it never changes, but it hides the distinction between Effect Events and real dependencies.
- The lint rules that stop you from passing an Effect Event to children do not apply. Nothing stops a teammate from passing the wrapper down as a prop.
useInsertionEffectis intended for CSS-in-JS libraries. Using it here relies on its timing, not on a documented purpose.
Treat the fallback as temporary. Give it a name that is easy to search for, and replace it with import { useEffectEvent } from 'react' once you upgrade. The two have the same call signature, so the replacement is mechanical.
Upgrade checklist
- Run
npm ls react react-dom eslint-plugin-react-hooks @types/reactand note the versions. - Upgrade React and React DOM to 19.2 or later, and upgrade the lint plugin and type packages.
- Replace every
experimental_useEffectEventimport withuseEffectEvent. - Replace any ref-based fallback with the real hook.
- Run the linter. Fix any Effect Event that appears in a dependency array, and any Effect Event called outside an Effect.
- Run your tests, focusing on Effects that connect, subscribe, or set timers.
Exercise
After upgrading React to 19.2 and changing your import to useEffectEvent, the linter warns that the Effect in ChatRoom is missing the dependency onConnected. What is the most likely cause, and what should you do?
Show answer
The installed eslint-plugin-react-hooks is too old to recognize the stable useEffectEvent name, so it treats onConnected as an ordinary function. Upgrade the plugin to the latest version. Do not add onConnected to the dependency array, because Effect Events must never be listed as dependencies.
Exercise
A component file starts with import { useEffect, experimental_useEffectEvent as useEffectEvent } from 'react';. What is the minimal change to move it to the stable API, and why does the rest of the file need no edits?
Show answer
Change the import to import { useEffect, useEffectEvent } from 'react';. The alias already made the file call the hook as useEffectEvent, and the stable hook has the same signature and behavior, so no call sites need to change.
Exercise
Your published component library declares the peer dependency "react": "^18.2.0 || ^19.0.0" and you want to start using useEffectEvent. Name two ways to avoid breaking existing users.
Show answer
Either raise the peer dependency range to ">=19.2.0" and publish the change as a major version, or keep the old range and use a ref-based fallback hook (for example one built on useRef and useInsertionEffect) until you drop support for older React versions. Do not import useEffectEvent while the peer range still allows versions that lack it.