JSX and the CSS prop
Configure the JSX runtime
Add @trousers/react as a direct dependency and set it as the JSX import source so JSX elements can accept css={styles} and $ props. With TypeScript, configure the automatic JSX runtime in tsconfig.json.
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@trousers/react"
}
}
If your bundler transforms JSX, give it the same import source. The bundler guide shows both configurations. For per-file opt-in, keep automatic JSX enabled in TypeScript and your bundler, and add the pragma at the top of the file.
/** @jsxImportSource @trousers/react */
import { css } from 'trousers';
const label = css({ fontWeight: 600 });
export function Status() {
return <span css={label}>Ready</span>;
}
The JSX runtime applies the compiled class names. The bundler adapter extracts the CSS, and the app must load the resulting stylesheet. With the standard React JSX runtime, use classnames.