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