Updates built from the previous state in React

React interview exercise on State, difficulty 2 of 3. Solve it in the editor beside a worked example, or cold in Interview mode with the example hidden; the tests run the moment you do.

Finish Likes: write bump() so that the "+3" button, which calls bump() three times in one handler, adds three. Also an async handler for "Later": it waits 10 ms (setTimeout) and then adds one, which must land correctly even if the user clicked "+1" in the meantime.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Interview mode hides the example: solve it from memory, without the hint or the solution, and it counts as solved cold. Progress is saved in your browser, and in your account if you sign in.

More State in React

All React exercises · Other languages and frameworks