#14useDebounce vs useThrottle
Overview
Create two custom hooks, useDebounce and useThrottle, to manage the frequency of function executions.
Requirements
- Implement two custom hooks:
useDebounce(value, delay)- Returns the updated value only after the specified
delayhas passed without further changes.
- Returns the updated value only after the specified
useThrottle(value, limit)- Returns the updated value at most once every
limitmilliseconds, regardless of how many times the original value changes during that period.
- Returns the updated value at most once every
- Both hooks should correctly handle rapid state changes without causing unnecessary re-renders.
Notes
- Use the
DELAYconstant fromconstants.tsfor both hooks.
Tests
- increments debounced and normal counters correctly
- increments throttled and normal counters correctly
- resets debounced and throttled counters instantly on Clear