React events use camelCase names: onClick, onChange, onSubmit. You pass functions, not strings—no inline onclick="..." HTML attributes.
Handler patterns
- Inline arrow:
onClick={() => setOpen(true)} - Named function:
function handleClick() { ... }thenonClick={handleClick} - Pass arguments:
onClick={() => remove(id)}
Synthetic events
React wraps native events for cross-browser consistency. Call event.preventDefault() on form submit when you handle submission in JS instead of a full page reload.
Self-check
- Why pass
onClick={handleClick}instead ofonClick={handleClick()}? - When do you need
preventDefaulton a form?
Challenge
Toggle panel
- Wire the button to flip
openstate. - Show details only when
openis true.
Done when: clicking the button shows and hides the details paragraph.