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.jsfiles with the JSX changed to_jsxcalls optimized for productionreact-jsxdev: Emit.jsfiles with the JSX changed to_jsxcalls for development onlypreserve: Emit.jsxfiles with the JSX unchangedreact-native: Emit.jsfiles with the JSX unchangedreact: Emit.jsfiles with JSX changed to the equivalentReact.createElementcalls
For example
This sample code:
tsxexport const HelloWorld = () => <h1>Hello world</h1>;
React: "react-jsx"[1]
tsxTryimport { jsx as _jsx } from "react/jsx-runtime";export const HelloWorld = () => _jsx("h1", { children: "Hello world" });
React dev transform: "react-jsxdev"[1]
tsxTryimport { 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"
tsxTryimport React from 'react';export const HelloWorld = () => <h1>Hello world</h1>;
React Native: "react-native"
tsxTryimport React from 'react';export const HelloWorld = () => <h1>Hello world</h1>;
Legacy React runtime: "react"
tsxTryimport 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>;