Find: setState During Render
Find the Mistake Medium
Question
What is wrong with this component?
Code
function Counter() {
const [count, setCount] = useState(0);
setCount(count + 1);
return <div>{count}</div>;
}
Hint
Where is setCount being called?
Explanation
setCount is called directly in the render body, not in an event handler or effect. This causes an infinite loop: render → setState → re-render → setState → ... The fix is to move it to an event handler: <button onClick={() => setCount(count + 1)}>.
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.