useThrottle
對值進行節流的React hook
Usage
即時編輯器
function Demo() { const [value, setValue] = useState<string>(); const throttledValue = useThrottle(value, 500); return ( <div> <input value={value} onChange={e => setValue(e.target.value)} placeholder="輸入值" style={{ width: 280 }} /> <p style={{ marginTop: 16 }}>節流值:{throttledValue}</p> </div> ); };
結果
節流值:
API
useThrottle
Returns
T
Arguments
| 參數名 | 描述 | 類型 | 預設值 |
|---|---|---|---|
| value | 要节流的值 | T (必填) | - |
| wait | 间隔时间 | number | undefined | - |
| options | 传递给 lodash.throttle 的选项 | _.ThrottleSettings | undefined | - |