JSX, Props and Composition
JSX is a description of UI, not the UI itself. Know what each value renders, how props are assembled, and the pitfalls of controlled inputs, children utilities, events and React 19's new DOM features.
Key points
- 1
JSX compiles to
jsx(type, props)calls that build plain element objects; components run later, when React renders them, so never call a component as a function. - 2
Props are assembled left to right like an object literal, so the last spread or attribute wins.
keyis never passed as a prop; in React 19refis. - 3
null,undefined,trueandfalserender nothing, but every number renders, socount && <X />can print 0 or NaN. - 4
An input is controlled when
valueis defined: it needsonChange, andvaluemust never switch between undefined and a string. - 5
Define components at module level. A component declared inside another is a new type every render and remounts with its state lost.
- 6
React events follow the React tree, so they bubble out of portals. Since React 17 they are delegated at the root and not pooled.
- 7
React 19 hoists
<title>,<meta>and<link>into the head, dedupes stylesheets withprecedence, and sets custom-element props as properties when possible.
Common traps
Destructuring defaults ignore
null; onlyundefinedtriggers them, anddefaultPropsno longer works on function components in React 19.Children.countandChildren.maptreat a fragment as a single child and count null and false, so Children-based APIs break easily.cloneElementreplaces handlers you pass instead of composing them, anddangerouslySetInnerHTMLnever sanitises.
Test yourself on JSX, Props and Composition
Ten questions, with the answer and explanation after each one.