Skip to content
Onsite

Write a useInterval hook that always calls the latest callback.

MediumP3Coding

Write a useInterval(callback, delay) hook that calls callback every delay milliseconds, as setInterval would, but that works correctly with React state.

Build a demo: a counter that increments every second, with controls to pause and to change the delay. The callback reads the current state, so a stale closure shows up as a counter stuck at 1.

Time box: 20 to 30 minutes.

Requirements

0 / 6

Stretch goals

0 / 3

Only after every requirement works.

Hints

Workspace

Your files are saved in this browser as you type.

When every requirement works, mark it complete to count it as solved.

Solution notes

How a strong candidate structures it, and what interviewers check.

Saved automatically