Lesson 1 of 80
A component is a function that returns UI. JSX is what lets that UI look like HTML while still being real JavaScript underneath.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 4
What does the JSX `<Greeting name="Ada" />` actually compile to?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
A component is just a JavaScript function. What makes it a React component is one convention: it returns a description of some UI instead of a number or a string.
JSX is the <div>...</div>-looking syntax you write that description in. It looks like HTML, but it isn't — it's sugar that compiles to plain function calls, before your code ever reaches the browser.
function Greeting({ name }) {
return <h1>Hello, {name}</h1>;
}
That JSX compiles to this — no magic, just a function call that returns a plain object describing "an h1 with this text":
function Greeting({ name }) {
return React.createElement("h1", null, "Hello, ", name);
}
Nothing here touches the DOM. Greeting({ name: "Ada" }) just returns a description — a React element, a plain object — the same way Math.max(1, 2) returns a number. React's renderer is the separate piece that later takes that description and turns it into real DOM nodes.
function Card() { return <div>Hi</div>; } — a component is just a function that returns a description of UI.
useEffect.return null; is a completely normal component — it renders nothing.<div> compiles to a string (a real HTML tag); <Greeting> compiles to a reference to your function. That's also why component names must start with a capital letter — lowercase would be read as an HTML tag."What does JSX compile to?" checks whether you actually understand a component as a function, not a template — and everything else in React (props, state, hooks, re-rendering) is a direct consequence of that one fact.