Skip to content
Back to Pathway
fundamentalsbeginner

JSX Compilation

JSX is a syntax extension for JavaScript that compiles into React.createElement or react/jsx-runtime function calls.

Mental Model

"The Translator: Writing JSX looks like HTML, but the compiler instantly translates it into standard JavaScript objects."

Interactive Engine Walkthrough

The Build Pipeline
load
source JSX · editable
swc
emitted JavaScript
import { jsx as _jsx } from "react/jsx-runtime";

_jsx("h1", {
  className: "title",
  children: "Hello"
})
tags 1·props 1

Change the tag, drop an attribute, add a second child: the emitted call changes with it. JSX is not HTML — it is the argument list of _jsx().

Reference Code Snippet

Component.jsx
JSX / React 19
1// This JSX:
2const element = <h1 className="title">Hello World</h1>;
3
4// Becomes this JS:
5const compiled = React.createElement(
6  'h1', 
7  { className: 'title' }, 
8  'Hello World'
9);
10
Technical Takeaways & Best Practices
  • 01.JSX is syntactic sugar that produces JavaScript objects representing DOM nodes or components.
  • 02.Expressions inside curly braces { } can evaluate any valid JavaScript expression.
  • 03.All tags must be closed, and adjacent JSX elements must be wrapped in a parent or Fragment <> </>.

01. Not HTML. Not String.

JSX looks like HTML, but it's a syntax extension for JavaScript. Browsers cannot read JSX. It must be compiled by a tool like **Babel** or **SWC**. Every tag you write becomes a function call that returns a "React Element" (a plain JavaScript object).

Transformation Flow

Source (.jsx)
→
Transpiler (SWC)
↓
Runtime (.js)

02. The Modern Transform

In older versions of React, you had to `import React` in every file because JSX compiled to `React.createElement`. In modern React (17+), the compiler automatically imports special functions like `_jsx` from the `react/jsx-runtime` package, making your code cleaner and bundles smaller.

Pro Tip

"Since JSX is just JavaScript, you can use any JS expression (math, functions, variables) inside curly braces . This is the ultimate power of React compared to template-based frameworks."