Skip to content

Commit 6aca8fe

Browse files
committed
docs: update jsx.transform.react.runtime option
1 parent dda4bf9 commit 6aca8fe

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

apps/website/content/docs/configuration/compilation.mdx

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,52 @@ If you are using typescript and decorators with `emitDecoratorMetadata` enabled,
365365

366366
#### jsc.transform.react.runtime
367367

368-
Possible values: `automatic`, `classic`. This affects how JSX source code will be compiled.
368+
Possible values: `automatic`, `classic`, `preserve`.
369369

370-
- Defauts to `classic`.
371-
- Use `runtime: automatic` to use a JSX runtime module (e.g. `react/jsx-runtime` introduced in React 17).
372-
- Use `runtime: classic` to use `React.createElement` instead - with this option, you must ensure that `React` is in scope when using JSX.
370+
Decides which runtime to use when transforming JSX.
371+
372+
- Defaults to `'classic'`.
373+
- Use `runtime: 'automatic'` to use a JSX runtime module (e.g. `react/jsx-runtime` introduced in React 17). This is the modern approach introduced in React 17+ that eliminates the need to manually import React in every file that uses JSX.
374+
375+
```json filename=".swcrc" copy
376+
{
377+
"jsc": {
378+
"transform": {
379+
"react": {
380+
"runtime": "automatic"
381+
}
382+
}
383+
}
384+
}
385+
```
386+
387+
- Use `runtime: 'classic'` to use the traditional JSX transform that relies on `React.createElement` calls - with this option, you must ensure that `React` is in scope when using JSX.
388+
389+
```json filename=".swcrc" copy
390+
{
391+
"jsc": {
392+
"transform": {
393+
"react": {
394+
"runtime": "classic"
395+
}
396+
}
397+
}
398+
}
399+
```
400+
401+
- Use `runtime: 'preserve'` to leave JSX syntax unchanged without transforming it.
402+
403+
```json filename=".swcrc" copy
404+
{
405+
"jsc": {
406+
"transform": {
407+
"react": {
408+
"runtime": "preserve"
409+
}
410+
}
411+
}
412+
}
413+
```
373414

374415
[Learn more here](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html).
375416

0 commit comments

Comments
 (0)