useDebounce
When the value changes, the hook will delay updating the state for a specific timeout. If the following change occurs before the timeout moment, the delay will restart until no change occurs within that timeout.
It has the exact mechanism with lodash.debounce, but this one is React hook.
Usually, it helps implement the components that need a delay time before executing some actions or events (such as the
Search
component) to prevent multiple requests to the server to save resources.
SearchInput.jsx
#
Optionsvalue: T | undefined
- Required
- The value is being tracked by the hook.
delay: number
- Required
- Delay time before updating
debouncedValue
#
ReturnsdebouncedValue: T | undefined
- The value is asynchronously updated