UNPKG

use-lodash-debounce-throttle

Version:

Bring debounce & throttle of lodash version to react-hooks

34 lines (29 loc) 700 B
--- name: use-throttle --- import { Playground } from 'docz'; import { useState, useEffect } from 'react'; import useThrottle from './use-throttle.ts'; # use-throttle ```js const throttledFn = useThrottle(func, [wait=0], [options={}]); ``` <Playground> {() => { const debouncedChange = useThrottle((v) => { console.log('throttled value', v); }, 500, { leading: false }); const fn = useThrottle(function (currentTarget) { console.log('currentTarget', currentTarget); }, 500); return ( <input type="text" onChange={(e) => { debouncedChange(e.target.value) fn(e.currentTarget); }} /> ) }} </Playground>