same as useEffect but will only be called once every maxWait in ms (defaults to 0ms)
Open console to see logs
const [count, setCount] = useState(0)
const onClick = () => setCount(count + 1)
useEffectThrottle(
() => {
console.log("count changed!")
},
[count],
{
maxWait: 1000, // 1s in ms
}
)
import { const useEffectThrottle: (callback: () => void, deps: unknown[] | undefined, options?: UseEffectThrottleOptions) => void
useEffectThrottle } from "@kaioken-core/hooks"
function useEffectThrottle(callback: () => void, deps: unknown[] | undefined, options?: UseEffectThrottleOptions): void
useEffectThrottle(() => {}, [], {
maxWait?: number | undefined
maxWait: 0,
})