React · Junior · Question 73 of 75
Why doesn't clicking <MyButton onClick={save} /> call save?
function MyButton({ label }) {
return <button>{label}</button>;
}- ✓Correct answer:
onClickis just a prop for a custom component;MyButtonmust pass it to the<button> - 2Custom components don't support events
- 3
onClickmust be written in lowercase for components
Explanation
Only built-in DOM elements turn onClick into a listener. The component must accept the prop and forward it: <button onClick={onClick}>.