useThrottle
React hooks that throttle value
Usage
Live Editor
function Demo() { const [value, setValue] = useState<string>(); const throttledValue = useThrottle(value, 500); return ( <div> <input value={value} onChange={e => setValue(e.target.value)} placeholder="Typed value" style={{ width: 280 }} /> <p style={{ marginTop: 16 }}>throttledValue: {throttledValue}</p> </div> ); }; render(<Demo/>);
Result
Loading...
API
useThrottle
Returns
T
Arguments
Argument | Description | Type | DefaultValue |
---|---|---|---|
value | the value need to throttle | T (Required) | - |
wait | wait time | number | undefined | - |
options | options passed to lodash.throttle | _.ThrottleSettings | undefined | - |