- React Compiler is a new compiler that is open sourced to get feedback from the community. It is a build-time only tool that automatically optimizes your React app. It works with plain JavaScript, and understands the Rules of React, so you don’t need to rewrite any code to use it.
- The compiler is currently released as rc, and is available to try out on React 17+ apps and libraries.
- The compiler is designed to compile functional components and hooks that follow the Rules of React.
- In order to optimize applications, React Compiler automatically memoizes your code.
You may be familiar today with memoization through APIs such asuseMemo,useCallback, andReact.memo. With these APIs you can tell React that certain parts of your application don’t need to recompute if their inputs haven’t changed, reducing work on updates.
While powerful, it’s easy to forget to apply memoization or apply them incorrectly. This can lead to inefficient updates as React has to check parts of your UI that don’t have any meaningful changes. - The compiler uses its knowledge of JavaScript and React's rules to automatically memoize values or groups of values within your components and hooks. If it detects breakages of the rules, it will automatically skip over just those components or hooks, and continue safely compiling other code.
- You can use React Compiler Playground in order to check how the code is compiled.
- The compiler is currently released as rc, and is available to try out on React 17+ apps and libraries. To install the RC, use:
npm install -D babel-plugin-react-compiler@rc eslint-plugin-react-hooks@^6.0.0-rc.1 - React Compiler works best with React 19 RC. If you are unable to upgrade, you can install the extra
react-compiler-runtimepackage which will allow the compiled code to run on versions prior to 19. However, note that the minimum supported version is 17.
npm install react-compiler-runtime@rc - You should also add the correct target to your compiler config, where target is the major version of React you are targeting:
// babel.config.js const ReactCompilerConfig = { target: '18' // '17' | '18' | '19' }; module.exports = function () { return { plugins: [ ['babel-plugin-react-compiler', ReactCompilerConfig], ], }; };
- React Compiler also powers an ESLint plugin. The ESLint plugin will display any violations of the rules of React in your editor. When it does this, it means that the compiler has skipped over optimizing that component or hook. This is perfectly okay, and the compiler can recover and continue optimizing other components in your codebase.
- You can try it out by installing
eslint-plugin-react-hooks@^6.0.0-rc.1.
npm install -D eslint-plugin-react-hooks@^6.0.0-rc.1 - See official editor setup guide for more details.
If you navigate to React Compiler Playground and open EnvironmentConfig section, you will see that there are plenty of options that React compiler offers.
Let's play around over some options that can help React Compiler to deliver better performance:
enableFunctionOutlining: truein environment config
This option is set to true by default, and it is the option responsible for automatic memoization. However, it is has some limitations and is not enough to ensure memoization for all scenarios.- Set
enableJsxOutlining: truein environment config ensures that memoization is done even if the map callback contains variables declared outside the callback block like in this example (see variablestyle).// @enableJsxOutlining export default function List({people}) { const style = useStyles(); const items = useMemo(() => people.map(({ id, name }) => ( <li key={id}> <Text name={name} style={style} /> </li> )), [people, style]); return ( <ul>{items}</ul> ); }
EnvironmentConfigis not editable in React Compiler Playground, but we can use// @enableJsxOutliningannotation to enable the flag. - Set
panicTresHold: nonesetting in your plugin options tocritical_errorsorall_errorsvalue in order to seeCannotPreserveMemoizationerrors.
This error occurs when React Compiler cannot guarantee us that the memoization level that we had stays the same after React compiler did his job.
As mentioned, by default React Compiler will just skip the components that it cannot memoize and if you still want to see those components, you can usepanicTresHoldsetting.const parsedOptions = {target: '18'} export const defaultOptions: PluginOptions = { compilationMode: 'infer', ..., panicTresHold: 'critical_errors' }
- Set
"validatePreserveExistingMemoizationGuarantees": truein environment config in order to seeCannotPreserveMemoizationerrors mentioned above.Actually this is recommended by React Compiler team.plugins: [ [ "babel-plugin-react-compiler", { ...config, envoronment: { validatePreserveExistingMemoizationGuarantees: true } } ] ]
- React Compiler Official Documentation
- React Compiler Playground
- React Compiler Working Group
- React Eslint guide
- Rules of React
- How to use React Compiler Tutorial
- React Compiler Internals - Presentation by Lydia Hallie at React Summit, June 2025.
- How to React Compiler - Presentation by Anton Nepsha at React Summit, June 2025.