description: Enable the React Compiler to automatically optimize component rendering.
description: Enable the React Compiler to automatically optimize component rendering.
version: experimental
---
---
Next.js includes support for the [React Compiler](https://react.dev/learn/react-compiler), a tool designed to improve performance by automatically optimizing component rendering. This reduces the need for manual memoization using `useMemo` and `useCallback`.
Next.js includes support for the [React Compiler](https://react.dev/learn/react-compiler/introduction), a tool designed to improve performance by automatically optimizing component rendering. This reduces the need for manual memoization using `useMemo` and `useCallback`.
Next.js includes a custom performance optimization written in SWC that makes the React Compiler more efficient. Instead of running the compiler on every file, Next.js analyzes your project and only applies the React Compiler to relevant files. This avoids unnecessary work and leads to faster builds compared to using the Babel plugin on its own.
Next.js includes a custom performance optimization written in SWC that makes the React Compiler more efficient. Instead of running the compiler on every file, Next.js analyzes your project and only applies the React Compiler to relevant files. This avoids unnecessary work and leads to faster builds compared to using the Babel plugin on its own.
...
@@ -20,15 +19,13 @@ To use it, install the `babel-plugin-react-compiler`:
...
@@ -20,15 +19,13 @@ To use it, install the `babel-plugin-react-compiler`:
npm install babel-plugin-react-compiler
npm install babel-plugin-react-compiler
```
```
Then, add `experimental.reactCompiler` option in `next.config.js`:
Then, add `reactCompiler` option in `next.config.js`:
```ts filename="next.config.ts" switcher
```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next'
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
const nextConfig: NextConfig = {
experimental: {
reactCompiler: true,
reactCompiler: true,
},
}
}
export default nextConfig
export default nextConfig
...
@@ -37,9 +34,7 @@ export default nextConfig
...
@@ -37,9 +34,7 @@ export default nextConfig
```js filename="next.config.js" switcher
```js filename="next.config.js" switcher
/** @type {import('next').NextConfig} */
/** @type {import('next').NextConfig} */
const nextConfig = {
const nextConfig = {
experimental: {
reactCompiler: true,
reactCompiler: true,
},
}
}
module.exports = nextConfig
module.exports = nextConfig
...
@@ -53,10 +48,8 @@ You can configure the compiler to run in "opt-in" mode as follows:
...
@@ -53,10 +48,8 @@ You can configure the compiler to run in "opt-in" mode as follows: