Loading homepage
Implement a React hook that limits how frequently a changing value is published, while retaining the latest value from a burst of updates. Unlike a debounce, ongoing changes must not continually postpone publication.
JavaScript and TypeScript use the same contract. Tests render real React components and cover state updates and lifecycle behavior.
Input: useThrottle("a", 100) Output: Returns "a" immediately and begins a 100 ms cooldown.
Input: Input changes to "ab", then "abc" during that cooldown Output: Keeps "a", then publishes "abc" at the deadline without extending it.
Input: After the cooldown ends without pending changes, input becomes "abcd" Output: Publishes "abcd" after its effect and begins the next cooldown.
Examples describe state after the corresponding React render or update.