arrow_backBACK TO DRILLS
Black BeltrenderinglockPREMIUM

React Renders Component Once Before Bailing Out on Same-Value setState

A component calls setCount(5) inside an onClick handler while count is already 5.

REACT_MODULE // 0x42
function Widget({ count, setCount }) {
console.log('Widget rendered');
return <button onClick={() => setCount(5)}>{count}</button>;
}

If count is already 5 when the button is clicked, how many times does "Widget rendered" print as a result of that single click?

lock

This Drill is Locked

This is a premium drill. Continue on to the next free drill in the sequence.

CONTINUE DRILLarrow_forward
BugDojo
BlogFAQ

© 2026. Carved in code.