useThrottle
React hook for throttled values and functions.
yarn add @corets/use-throttlenpm install --save @corets/use-throttleuseThrottle()
import React, { useState, useEffect } from "react"
import { useThrottle } from "@corets/use-throttle"
const Example = () => {
const [input, setInput] = useState("")
const throttledInput = useThrottle(input, 300)
const handleSearch = () => {
// fetch some data based on input...
}
const handleChange = (e) => setInput(e.target.value)
// react to changes of the debounced input
useEffect(handleSearch, [throttledInput])
return (
<input type="text" onChange={handleChange} />
)
}Last updated
Was this helpful?