Components and JSX
7 pages · ~4 min✓ Reviewed
Start here. Next up: State and Props.
Components and JSX Mental Model
1. What a Component Is
- A function component takes props, returns JSX
- Name starts with a capital, or
<card />is an HTML tag - UI = f(props, state): body is pure, no side effects
2. JSX Is Objects
- JSX is sugar for
jsx()calls returning plain element objects, not DOM nodes
jsx
const el = <h1 className="t">Hi</h1>; // compiles to const el = jsx("h1", { className: "t", children: "Hi" });
el is a plain object, not a DOM node
3. Props and Renders
- Props or state change
- Function re-called
- New element tree
- Diff, patch DOM