Loading homepage
Build a React hook that delays publishing a changing value until it has stayed unchanged for a specified period. This is useful for search inputs that should not trigger work on every keystroke.
The JavaScript and TypeScript variants share the same contract. Tests render real React components and exercise updates and lifecycle cleanup.
Input: useDebounce("cat", 200) Output: Returns "cat" immediately.
Input: Change the input from "cat" to "cats" with delay 200 Output: Returns "cat" until 200 ms have passed without another change, then returns "cats".
Input: Change "a" to "ab", then to "abc" before the delay expires Output: Only "abc" is published after the final quiet period.
Examples describe the current return value after the corresponding React render or event.