React Compiler: Do You Still Need useMemo?
What the React Compiler does, how to turn it on in Next.js, when useMemo and useCallback still matter, and the mistakes that stop it from optimizing your code.

What is the React Compiler?
The React Compiler is a build-time tool from the React team that adds memoization to your components and hooks for you. You may remember it by its old codename, React Forget. Instead of you wrapping values in useMemo and functions in useCallback, the compiler analyzes how data flows through each component and caches the parts that don't need to be recomputed.
We've spent years fighting re-renders by hand. Every senior React dev has a story about a dependency array that was missing one value, or a useCallback that did nothing because a parent passed a fresh object every render. The compiler's pitch is simple: write plain React, and let the build step handle the caching.
It runs as a Babel plugin, so it works wherever your build pipeline can run Babel or has an integration for it. That includes Next.js, Vite and Expo, which means the same idea applies to React Native apps too.
How the React Compiler works
The compiler reads each component and hook, builds a model of which values depend on which inputs, and rewrites the output so that derived values, JSX and callbacks are only recreated when their inputs actually change. The result is close to what you'd get if you placed useMemo and useCallback everywhere, and placed them correctly.
One detail surprised me in practice. The compiler is smart enough to memoize not only at the component boundary, the way React.memo does, but at a finer level inside components and hooks. A single expensive piece of JSX can be cached while the rest of the component re-runs. That's granularity you rarely bother with when doing it by hand.
It can only do this safely if your code follows the Rules of React: components and hooks are pure during render, props and state are treated as immutable, and hooks are called unconditionally at the top level. When the compiler can't prove a component follows those rules, it skips that component and leaves it as is. It won't crash your build. You just don't get the optimization there.
Field report: removing useMemo from a large dashboard
I wanted to know if manual optimization is truly dead, so I tested the compiler on a heavy dashboard with 50+ charts. I enabled the compiler and removed all the useMemo hooks.
The result was a 15% reduction in code volume and identical, sometimes better, performance metrics. Less code, same speed. That's the trade you want from any tool.
The bigger win was readability. Component bodies went back to looking like plain functions. New code didn't need a debate about whether a value was worth memoizing. Here's what changed day to day:
- No more dependency array management
- Cleaner, more readable component bodies
- Setup was trivial in Next.js 15 and later
- Fewer code review comments about missing or pointless memoization
How to enable the React Compiler in Next.js
In recent Next.js versions, setup is a config flag plus one dev dependency. Install babel-plugin-react-compiler, then set reactCompiler: true in your next.config file. Depending on your Next.js version, that option lives at the top level or under experimental, so check the docs for the version you run. Next.js applies the compiler only to the files that need it, so your build doesn't slow down across the board.
Outside Next.js, add babel-plugin-react-compiler to your Babel config, or use your bundler's documented integration. For Vite that usually means passing the plugin through the React plugin's Babel options. Recent Expo SDKs also support it for React Native projects.
You don't have to go all in on day one. The compiler supports an annotation mode where only components or hooks marked with the 'use memo' directive get compiled. You can also opt a single component out with the 'use no memo' directive while you track down a problem. That makes gradual adoption on a big codebase realistic.
Turn on the React hooks ESLint plugin too. The compiler-related lint rules flag code that breaks the Rules of React, which is exactly the code the compiler will skip. Fix the lint errors and more of your app gets optimized.
When you still need useMemo and useCallback
The compiler makes manual memoization unnecessary in most components, but the hooks aren't deprecated and they still have a few jobs.
The main one is controlling effects. If a value is a dependency of a useEffect and you need precise control over when that effect fires, an explicit useMemo or useCallback makes that intent obvious to the next developer. The React team's own guidance is to treat manual memoization as an escape hatch for cases like this.
Existing memoization is also fine to leave in place. The compiler works alongside it, so there's no need for a big cleanup PR before you turn the compiler on. Remove the hooks as you touch files, and measure before and after if a screen is performance-critical.
Finally, the compiler only caches. It doesn't make a slow algorithm fast. If a component sorts ten thousand rows on every input change, memoization won't help the first computation. You still need virtualization, pagination or a better data structure for that.
Common mistakes that break compiler optimizations
It's not bulletproof. If you have side effects in your render phase, which you shouldn't have anyway, the compiler may cache them in ways that change how often they run. Code that 'worked' only because it re-ran on every render can quietly behave differently. Strict Mode compliance is now mandatory in my book. If your app doesn't survive Strict Mode's double rendering, it isn't ready for the compiler.
Watch for these patterns, since they either block optimization or cause surprising behavior:
- Mutating props, state or objects created in a previous render instead of creating new ones
- Reading or writing ref.current during render instead of in effects or event handlers
- Calling hooks conditionally or inside loops
- Relying on a value being recreated every render to trigger an effect
- Third-party libraries that mutate objects you pass in, which the compiler can't see
Is the React Compiler worth it?
For most React and Next.js apps, yes. You write less code, you stop arguing about dependency arrays, and you get memoization that's at least as good as what a careful human would write. My dashboard test is the reason I default to it on new projects.
The cost is discipline. Your components need to be pure and your app needs to pass Strict Mode. If your codebase is full of render-phase side effects, fix those first. You'll get a more predictable app out of it whether or not you turn the compiler on.
It also changes how you review code. Instead of asking 'did you memoize this?', the question becomes 'does this follow the Rules of React?'. That's a better question, and the lint rules answer most of it for you. The same habit pays off if you use AI coding agents, since a clear rule set and a linter give them something concrete to check their output against.
Frequently Asked Questions
Does the React Compiler replace useMemo and useCallback?
For most components, yes. The compiler adds memoization automatically at build time, so you rarely need to write these hooks. They still exist and are useful as an escape hatch, mainly when you need exact control over when an effect re-runs.
Do I need React 19 to use the React Compiler?
It works best with React 19. Older React versions can be supported with an extra runtime package and a target setting in the compiler config. Check the official React Compiler docs for the versions currently supported.
How do I turn on the React Compiler in Next.js?
Install babel-plugin-react-compiler and set reactCompiler: true in next.config. In some Next.js versions the flag sits under experimental, so match it to the docs for your version.
Should I remove existing useMemo calls after enabling the compiler?
You don't have to. The compiler works alongside existing memoization. Removing it makes code shorter and easier to read, so do it gradually as you touch files and measure performance-critical screens before and after.
Why isn't the React Compiler optimizing my component?
Usually because the component breaks a Rule of React, such as mutating props, reading refs during render or calling hooks conditionally. The compiler skips code it can't prove is safe. Enable the React hooks ESLint rules to find the cause.
Keep reading
All guides →
Next.js Server Actions: A Practical Guide
What Next.js Server Actions are, how to use them with forms, how to validate and secure them, and when an API route is still the better choice for the job.

Next.js Image Optimization: A Practical next/image Guide
How to optimize images in Next.js: next/image sizing, priority for LCP, AVIF and WebP, remote patterns, and custom loaders for CMS and CDN images.

AI in Cybersecurity: How Automated Threat Detection and Response Is Transforming Digital Defense in 2026
Cyberattacks are faster, smarter, and more frequent than ever. AI-powered cybersecurity systems are the only defense capable of matching the speed and sophistication of modern threats. Here is how AI is reshaping digital security.