Open almost any React codebase written in the last few years, and you'll find it: useMemo around a simple .filter(), useCallback around every handler, memo() on components that render twice a day.
We added all that code to stop unnecessary re-renders. Now React Compiler does memoization automatically at build time. So the obvious question is: do you still need useMemo and useCallback after React Compiler?
Short answer: for most new code, no. But there are a few cases where removing them will hurt you, and a few things the compiler will never fix for you.
This post covers both, with code you can compare side by side.
📌 This is part 2 of my React Performance in Practice series. In part 1, I showed how to find unnecessary re-renders with React DevTools. This post explains what to do once you find them.
TL;DR
- React Compiler memoizes components, values, and callbacks for you, often more precisely than hand-written hooks.
- In new code, write plain React and let the compiler handle memoization.
- Keep
useMemo / useCallbackwhen a value is an effect dependency, and you need exact control over when the effect runs. - The compiler assumes you follow the Rules of React. Code that mutates props or reads refs during render can break or be skipped.
- The compiler doesn't fix bad state placement, chatty context, huge lists, or slow data fetching.
What does React Compiler actually do?
React Compiler is a build-time tool that analyzes your components and hooks and automatically inserts memoization. It caches computed values, callbacks, and JSX, and recalculates them only when their inputs change. You get the effect of useMemo, useCallback, and memo() without writing them.
It runs as a Babel plugin (babel-plugin-react-compiler). It reached its stable 1.0 release in October 2025 and works best with React 19.
Here's a typical component written the "careful" way:
jsx
import { useMemo, useCallback, memo } from 'react'; function ProductList({ products, query, onAddToCart }) { const filtered = useMemo( () => products.filter((p) => p.name.toLowerCase().includes(query.toLowerCase()) ), [products, query] ); const handleAdd = useCallback((id) => onAddToCart(id), [onAddToCart]); return ( <ul> {filtered.map((p) => ( <ProductRow key={p.id} product={p} onAdd={handleAdd} /> ))} </ul> ); } const ProductRow = memo(function ProductRow({ product, onAdd }) { return ( <li> {product.name} <button onClick={() => onAdd(product.id)}>Add</button> </li> ); }); And here's the same component with the compiler turned on:
jsx
function ProductList({ products, query, onAddToCart }) { const filtered = products.filter((p) => p.name.toLowerCase().includes(query.toLowerCase()) ); return ( <ul> {filtered.map((p) => ( <ProductRow key={p.id} product={p} onAdd={onAddToCart} /> ))} </ul> ); } function ProductRow({ product, onAdd }) { return ( <li> {product.name} <button onClick={() => onAdd(product.id)}>Add</button> </li> ); } Same behavior, less code, and nothing to keep in sync. No dependency arrays to forget.
Under the hood, the compiled output looks roughly like this (simplified):
js
JavaScript function ProductList(props) { const $ = _c(6); // compiler-managed cache slots const { products, query, onAddToCart } = props; let filtered; if ($[0] !== products || $[1] !== query) { filtered = products.filter(/* ... */); $[0] = products; $[1] = query; $[2] = filtered; } else { filtered = $[2]; } // JSX is cached the same way } One detail I like here: the compiler can memoize things after an early return or inside conditions. Hooks can't go there so that the compiler can be more precise than hand-written useMemo.
So, should you delete every useMemo and useCallback?
Not blindly. For new code, write it without manual memoization. For existing code, the React team recommends leaving current useMemo / useCallback in place and removing them only after testing, because removing them can change what the compiler produces.
Here's the quick decision table I use:
The next two sections explain the rows that catch people out.
When does useMemo still matter? Effect dependencies
useMemo and useCallback still matter when a value feeds a useEffect and correctness depends on that value staying stable. The compiler's memoization is a performance optimization, not a guarantee, so if your effect must not re-run, make that explicit.
Classic example: a chat room that reconnects whenever options change.
jsx
function ChatRoom({ roomId, serverUrl }) { const options = { roomId, serverUrl }; // new object every render useEffect(() => { const connection = createConnection(options); connection.connect(); return () => connection.disconnect(); }, [options]); // 😬 relies on memoization to avoid reconnecting } The compiler will probably memoize options. But "probably" isn't what you want for a WebSocket connection.
Best fix: don't need memoization at all. Move the object inside the effect and depend on primitives(the React docs cover this pattern in Removing Effect Dependencies):
jsx
function ChatRoom({ roomId, serverUrl }) { useEffect(() => { const connection = createConnection({ roomId, serverUrl }); connection.connect(); return () => connectiondisconnect(); }, [roomId, serverUrl]); // ✅ only reconnects when these change } If you can't restructure it (for example, the object comes from a custom hook that other code also uses), keep an explicit useMemo. This is exactly the escape hatch it's meant for:
jsx
const options = useMemo(() => ({ roomId, serverUrl }), [roomId, serverUrl]); Rule of thumb: if removing memoization would change behavior, not just speed, keep it explicit.
Why does the compiler skip some components?
React Compiler assumes your code follows the Rules of React: components are pure, props and state are treated as immutable, and refs aren't read during render. When it detects a violation, it skips optimizing that component. When it can't detect one, you can end up with stale UI.
Here's a bug I see a lot:
jsx
function Leaderboard({ scores }) { scores.sort((a, b) => b.value - a.value); // ❌ mutates a prop return ( <ol> {scores.map((s) => ( <li key={s.id}>{s.name}: {s.value}</li> ))} </ol> ); } .sort() mutates the array in place. Without the compiler, this "works" by accident. With caching, mutated inputs are exactly what leads to confusing bugs.
The fix is one word:
jsx
const sorted = scores.toSorted((a, b) => b.value - a.value); // ✅ returns a new array Other common offenders:
- Reading
ref.currentduring render instead of in effects or handlers - Mutating an object from state and then calling
setStatewith the same reference - Side effects such as analytics calls or
localStoragewrites in the render body
Tip: Install the latest eslint-plugin-react-hooks. Its recommended config now includes compiler-aware rules that flag these patterns before they reach production.
What React Compiler will NOT fix
This is the part most "React Compiler explained" posts skip. Memoization stops unnecessary work. It doesn't make necessary work cheaper, and it doesn't fix architecture.
When we run performance audits on production React apps, the real bottleneck is usually one of these, and none of them go away with the compiler:
- State that lives too high. If a search input's state lives in your root layout, the layout re-renders on every keystroke. Move state closer to where it's used.
- Context that changes constantly. Every consumer re-renders when a context value changes. Split fast-changing values (cursor position, timers) from slow ones (user, theme).
- Rendering thousands of rows. Caching doesn't help if 5,000 DOM nodes are on screen. Use virtualization, for example,
[react-window](https://github.com/bvaughn/react-window)or TanStack Virtual. - Slow data fetching. Request waterfalls, missing caching, and oversized API payloads are network problems, not render problems.
- Large bundles. The compiler doesn't code-split for you. Lazy-load heavy routes and libraries.
If your app still feels slow after turning the compiler on, start with this list. It's also where React performance optimization work usually pays off the most, because fixing one of these often matters more than fifty useMemo calls.
How to check the compiler is working
- React DevTools: optimized components show a "Memo" badge in the Components tab.
- ESLint: fix anything the compiler-related rules in
eslint-plugin-react-hooksreport. - Profiler: record the same interaction before and after enabling the compiler and compare commit counts. This is the same workflow from part 1.
- Opt out to debug: If a component behaves strangely, add
"use no memo"at the top of its function to skip compilation for just that component while you investigate.
Quick setup
Next.js (install babel-plugin-react-compiler first; see the Next.js reactCompiler docs):
js
// next.config.js const nextConfig = { reactCompiler: true, }; module.exports = nextConfig; Vite:
js
// vite.config.js import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [ react({ babel: { plugins: ['babel-plugin-react-compiler'], }, }), ], }); On React 17 or 18? You'll also need the react-compiler-runtime package and the target option set in the compiler config. Check the official docs for your version.
Migration checklist for an existing codebase
- [ ] Upgrade
eslint-plugin-react-hooksand fix Rules of React violations first - [ ] Enable the compiler on one folder or route (use
compilationMode: 'annotation'with"use memo"if you want gradual rollout) - [ ] Run your test suite and click through critical flows
- [ ] Compare before and after with the React Profiler
- [ ] Expand to the whole app
- [ ] Remove old
useMemo / useCallback / memo()one file at a time, testing as you go - [ ] Keep explicit memoization wherever an effect depends on stable references
Wrapping up
React Compiler changes the default. Instead of asking "should I memoize this?", you write plain React and only reach for useMemo or useCallback when stability affects correctness, not just speed.
The bigger wins still come from getting the fundamentals right: state in the right place, lean context, virtualized lists, and fast data fetching.
Now I'm curious: have you turned on React Compiler in a real project yet? Did you delete your useMemo calls, or are you keeping them "just in case"? Tell me in the comments 👇
Next in this series: how to fix slow React Context without reaching for a state library. Follow so you don't miss it.
