Skip to content

Latest commit

 

History

History

use-throttle

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

useThrottle(value, delay)

A hook for throttling the updates of a value.

function App() {
    const [count, setCount] = useState(0)
    const throttledCount = useThrottle(count, 1000)
    const onClick = e => setCount(count + 1)

    useEffect(() => {
        console.log(`Value updated to ${throttledCount}`)
    }, [throttledCount])

    return (
        <div>
            <button onClick={onClick}>Increment</button>
            <code>currentValue: {throttledCount}</code>
        </div>
    )
}

Edit useThrottle