Simulate useState: start at 0, increment twice, print final value.
Ready — edit the code above and click Run.
let state = 0;
function setState(updater) {
state = typeof updater === "function" ? updater(state) : updater;
}
setState(s => s + 1);
setState(s => s + 1);
console.log(state);
Try solving on your own first, then reveal the official answer.
Functional updates avoid stale state—critical in async React interview answers.