Skip to content

Commit 8bcb2da

Browse files
potetoAhmedBaset
authored andcommitted
[compiler] Move React 17/18 section to its own subheading (#7230)
Currently it's a little hidden, let's move it to its own subheading for more prominence
1 parent c7e24b5 commit 8bcb2da

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/content/learn/react-compiler.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,31 @@ const ReactCompilerConfig = {
184184

185185
When you have more confidence with rolling out the compiler, you can expand coverage to other directories as well and slowly roll it out to your whole app.
186186

187+
### Using React Compiler with React 17 or 18 {/*using-react-compiler-with-react-17-or-18*/}
188+
189+
React Compiler works best with React 19 RC. If you are unable to upgrade, you can install the extra `react-compiler-runtime` package which will allow the compiled code to run on versions prior to 19. However, note that the minimum supported version is 17.
190+
191+
<TerminalBlock>
192+
npm install react-compiler-runtime@experimental
193+
</TerminalBlock>
194+
195+
You should also add the correct `target` to your compiler config, where `target` is the major version of React you are targeting:
196+
197+
```js {3}
198+
// babel.config.js
199+
const ReactCompilerConfig = {
200+
target: '18' // '17' | '18' | '19'
201+
};
202+
203+
module.exports = function () {
204+
return {
205+
plugins: [
206+
['babel-plugin-react-compiler', ReactCompilerConfig],
207+
],
208+
};
209+
};
210+
```
211+
187212
#### New projects {/*new-projects*/}
188213

189214
If you're starting a new project, you can enable the compiler on your entire codebase, which is the default behavior.
@@ -369,16 +394,6 @@ To report issues, please first create a minimal repro on the [React Compiler Pla
369394

370395
You can also provide feedback in the React Compiler Working Group by applying to be a member. Please see [the README for more details on joining](https://github.com/reactwg/react-compiler).
371396

372-
### What does the compiler assume? {/*what-does-the-compiler-assume*/}
373-
374-
React Compiler assumes that your code:
375-
376-
1. Is valid, semantic JavaScript.
377-
2. Tests that nullable/optional values and properties are defined before accessing them (for example, by enabling [`strictNullChecks`](https://www.typescriptlang.org/tsconfig/#strictNullChecks) if using TypeScript), i.e., `if (object.nullableProperty) { object.nullableProperty.foo }` or with optional-chaining `object.nullableProperty?.foo`.
378-
3. Follows the [Rules of React](https://react.dev/reference/rules).
379-
380-
React Compiler can verify many of the Rules of React statically, and will safely skip compilation when it detects an error. To see the errors we recommend also installing [eslint-plugin-react-compiler](https://www.npmjs.com/package/eslint-plugin-react-compiler).
381-
382397
### How do I know my components have been optimized? {/*how-do-i-know-my-components-have-been-optimized*/}
383398

384399
[React Devtools](/learn/react-developer-tools) (v5.0+) has built-in support for React Compiler and will display a "Memo ✨" badge next to components that have been optimized by the compiler.

0 commit comments

Comments
 (0)