React quick reference

Common patterns on one page.

PatternExample
Show if true{isOpen && <Menu />}
Either/or{ok ? <A /> : <B />}
List{items.map((x) => <Row key={x.id} />)}
EventonClick={() => save(id)}
Stateconst [v, setV] = useState(0)
Update from oldsetV((old) => old + 1)
Child contentfunction Card({ children })

Hooks must be called at the top level of a component, and never inside a loop or an if.

โ† More hooks and routingReact learning path โ†’