JSX Elements Are Just Objects
What you'll learn: JSX syntax isn't magic—it compiles down to plain JavaScript objects you can treat like any other data.
The Core Idea
When you write <div>Hello</div> in React, you might think it's HTML embedded in JavaScript. It's not. JSX is syntactic sugar that Babel compiles into a function call: React.createElement('div', null, 'Hello'). That function returns a plain JavaScript object describing what you want to render.
This means JSX elements are just data. You can store them in variables, pass them as arguments, return them from functions, put them in arrays, or manipulate them like any other value.
Why This Matters for Slots
When you pass JSX as a prop (the slot pattern you just learned), you're literally passing an object:
const header = <h1>Welcome</h1>; // Just an object!
const footer = <p>© 2024</p>; // Another object!
<Card header={header} footer={footer} />
You're not passing "components" or "DOM elements"—you're passing JavaScript objects that describe what to render. This is why slots work: props can hold any JavaScript value, including these element objects.
Practical Implications
Because JSX elements are objects, you can:
- Store them before rendering:
const elem = <Button />; - Conditionally create them:
const content = isLoading ? <Spinner /> : <Data />; - Pass them around like arguments
- Even inspect their properties (though you rarely need to)
Key Takeaway: JSX elements are plain JavaScript objects created by React.createElement(), which is why you can store, pass, and manipulate them like any other data—making patterns like slots and render props possible.