Do I still need useMemo? Trying the React Compiler
React Compiler 1. 0 was released on October 7. It's a build-time tool that adds memoization to your components and hooks for you.
React Compiler 1.0 was released on October 7. It’s a build-time tool that adds memoization to your components and hooks for you. The promise is that you stop writing useMemo, useCallback and memo by hand, and the app still avoids unnecessary re-renders.
So, is that true?
What it actually generates
Take a simple component:
export function ProductList({ products, filter }) {
const visible = products.filter((p) => p.name.includes(filter));
return (
<ul>
{visible.map((p) => <li key={p.id}>{p.name}</li>)}
</ul>
);
}
Running it through the compiler gives you roughly this (trimmed):
import { c as _c } from 'react/compiler-runtime';
export function ProductList(t0) {
const $ = _c(7); // a small cache for this component
const { products, filter } = t0;
let t1;
if ($[0] !== filter || $[1] !== products) {
// filter and map only run when one of the inputs changed
// ...
$[0] = filter;
$[1] = products;
$[2] = t1;
} else {
t1 = $[2];
}
// the <ul> element is cached the same way
// ...
}
That’s more fine-grained than most of us would write by hand. Each computed value and each JSX element gets its own cache slot, and it’s only recalculated when the values it depends on change. Since the JSX itself is cached, child components get the same element back and skip re-rendering, much like wrapping them in memo.
Setting it up
npm install --save-dev --save-exact babel-plugin-react-compiler@latest
For Vite with @vitejs/plugin-react, add it as a Babel plugin:
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [
react({
babel: {
plugins: ['babel-plugin-react-compiler'],
},
}),
],
});
In Next.js it’s a single reactCompiler option in the config, and Expo SDK 54 turns it on by default.
It works with React 17 and 18 as well. Set a target in the plugin options and add the react-compiler-runtime package:
plugins: [['babel-plugin-react-compiler', { target: '18' }]],
Note the —save-exact. The React team recommends pinning the version, because a change in how the compiler memoizes can occasionally change when an effect fires. Upgrade it on purpose, with tests, not through a caret range.
Code that breaks the rules
The compiler assumes your code follows the Rules of React: components are pure, hooks are called unconditionally, props and state aren’t mutated. If it spots a clear violation, it skips that component and leaves it exactly as written:
function Conditional({ show }) {
if (show) {
const [x] = useState(0); // hook inside a condition
}
return null;
}
// Not compiled: "Hooks must always be called in a consistent order,
// and may not be called conditionally."
The build doesn’t fail. That component just doesn’t get optimized.
But it doesn’t catch everything. A component that calls items.sort() on a prop compiled without complaint when I tried it. That kind of mutation was always a bug, but memoization can make it show up in new ways. So turn on the lint rules: eslint-plugin-react-hooks 7 includes compiler-based rules in its recommended preset, such as set-state-in-render, set-state-in-effect and refs. They’re useful even if you don’t enable the compiler.
// eslint.config.js
import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';
export default defineConfig([reactHooks.configs.flat.recommended]);
If one component misbehaves after enabling the compiler, you can opt it out while you investigate:
function LegacyWidget(props) {
'use no memo';
// ...
}
So, do I still need useMemo?
For new code, mostly not. Write plain components and let the compiler handle it.
The exception is when you need a value to stay the same object on purpose, usually because it’s an effect dependency:
const options = useMemo(() => ({ responsive: true, data }), [data]);
useEffect(() => {
chart.update(options);
}, [options]);
The compiler would probably memoize options here too. But if the effect depends on it, saying so explicitly is clearer, and it’s what the React team recommends: keep useMemo and useCallback where you need precise control.
For existing code, leave your useMemo and useCallback calls alone. The compiler works fine with them, and removing them can change what it generates. If you want to clean them up, do it gradually, with tests, not as one big find-and-delete.
Was it worth turning on?
The React team reported up to 12% faster initial loads and navigations on the Meta Quest Store, and some interactions more than 2.5× faster. Your numbers depend on how much manual memoization you already had. Apps that never bothered with memo see the biggest change. Apps that were carefully tuned by hand see less, but they get to stop maintaining all those dependency arrays, which is a win of its own.