Predict Event Handler Result
Predict Output Easy
Question
After clicking the button once, what is displayed?
Code
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
);
}
// Initial display: "Clicked 0 times"
// After one click: ?
Hint
count starts at 0, and each click adds 1.
Explanation
Initially count is 0, showing "Clicked 0 times". One click calls setCount(0 + 1) = 1, triggering a re-render that shows "Clicked 1 times".
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.