TSConfig
jsx
Controls how JSX constructs are emitted in JavaScript files.
This only affects output of JS files that started in .tsx
files.
react-jsx
: Emit.js
files with the JSX changed to_jsx
calls optimized for productionreact-jsxdev
: Emit.js
files with the JSX changed to_jsx
calls for development onlypreserve
: Emit.jsx
files with the JSX unchangedreact-native
: Emit.js
files with the JSX unchangedreact
: Emit.js
files with JSX changed to the equivalentReact.createElement
calls
For example
This sample code:
tsx
export const HelloWorld = () => <h1>Hello world</h1>;
React: "react-jsx"
[1]
tsxTry
import { jsx as _jsx } from "react/jsx-runtime";export const HelloWorld = () => _jsx("h1", { children: "Hello world" });
React dev transform: "react-jsxdev"
[1]
tsxTry
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";const _jsxFileName = "/home/runner/work/TypeScript-Website/TypeScript-Website/packages/typescriptlang-org/index.tsx";export const HelloWorld = () => _jsxDEV("h1", { children: "Hello world" }, void 0, false, { fileName: _jsxFileName, lineNumber: 9, columnNumber: 32 }, this);
Preserve: "preserve"
tsxTry
import React from 'react';export const HelloWorld = () => <h1>Hello world</h1>;
React Native: "react-native"
tsxTry
import React from 'react';export const HelloWorld = () => <h1>Hello world</h1>;
Legacy React runtime: "react"
tsxTry
import React from 'react';export const HelloWorld = () => React.createElement("h1", null, "Hello world");
This option can be used on a per-file basis too using an @jsxRuntime
comment.
Always use the classic runtime ("react"
) for this file:
tsx
/* @jsxRuntime classic */export const HelloWorld = () => <h1>Hello world</h1>;
Always use the automatic runtime ("react-jsx"
) for this file:
tsx
/* @jsxRuntime automatic */export const HelloWorld = () => <h1>Hello world</h1>;