Checkpoint · 2 files changed
  • profile.png
Why does the search box lag when I type? Here’s the profile.

Every keystroke calls useResults, and it fetches right away. Typing react sends five requests and renders five result lists, which is what your profile shows.

Debounce the value, not the handler:

  • The input stays instant because it still updates on every key.
  • The search waits for a short pause, so one request goes out instead of five.

Then pass useDebouncedValue(query, 250) to useResults instead of query.

Nova 3 · Medium
Checkpoint · 1 file changed
Nice. Can you add a test for it?

Fake timers keep it fast and exact. The test types two letters and checks that the value holds until 250 ms have passed.

2/2
Nova 3 · Medium