Quick Start
Run JSX/TSX files directly:Run JSX
JSX Transformation
Bun transforms JSX elements into function calls:JSX input
Output (classic runtime)
Output (automatic runtime)
JSX Runtimes
Bun supports multiple JSX transformation modes:Classic Runtime (React.createElement)
Default behavior for React:Classic runtime
tsconfig.json
Automatic Runtime (react/jsx-runtime)
Modern React 17+ runtime:Automatic runtime
tsconfig.json
Development Runtime
Includes debug information:tsconfig.json
__source and __self props for better debugging.
Preserve
Leaves JSX unchanged (for further processing):tsconfig.json
Configuration
tsconfig.json
Configure JSX behavior:tsconfig.json
Runtime Configuration
Override JSX settings programmatically:Runtime JSX config
Custom JSX Factories
Use JSX with any framework:Preact
tsconfig.json
Preact JSX
Custom h() function
tsconfig.json
Custom h() function
Vue JSX
tsconfig.json
Solid.js
tsconfig.json
JSX Features
Children
JSX children
Fragments
Fragments
Spread Attributes
Spread attributes
Conditional Rendering
Conditional rendering
Event Handlers
Event handlers
Ref Attributes
Refs
Namespaced Attributes
Namespaced attributes
TypeScript + JSX (TSX)
Combine TypeScript types with JSX:TypeScript JSX
Generic Components
Generic components
Type Assertions in JSX
Type assertions
JSX Performance
Automatic Import Optimization
Bun automatically imports JSX functions only when needed:Automatic imports
Static Children Optimization
Static optimization
React Fast Refresh
Bun supports React Fast Refresh for hot reloading:React Fast Refresh
src/runtime.zig:147 - React Fast Refresh feature flag
JSX Outside React
Use JSX with any virtual DOM library:Minimal JSX Runtime
Custom JSX runtime
tsconfig.json
DOM JSX
Create real DOM elements:DOM JSX
Debugging JSX
Inspecting Transformed Code
View transpiled output
Source Maps
Bun generates inline source maps for JSX:Original source
JSX Debug Mode
Debug JSX transform
Implementation
JSX transformation implementation:- Parser:
src/js_parser.zig- Parses JSX syntax - Printer:
src/js_printer.zig- Generates function calls - Runtime:
src/runtime.zig:159- Auto-import JSX configuration - Options:
src/options.zig- JSX pragma configuration
Feature Flags
Runtime JSX configuration (src/runtime.zig:159)
Common Patterns
Conditional Class Names
Conditional classes
Render Props
Render props
Component Composition
Component composition
Troubleshooting
React is not defined
Error
tsconfig.json
JSX not transforming
Ensure file has.jsx or .tsx extension:
Custom pragma not working
Checktsconfig.json is in project root and properly formatted.
Related
- TypeScript - TSX configuration
- Loaders - JSX loader details
- Watch Mode - Hot reload with JSX
- React Fast Refresh - React docs