useEffectDebounce

same as useEffect but will only be called once every maxWait in ms after all changes are finished (defaults to 0ms)

Demo

Open console to see logs

count: 0

Usage

const [count, setCount] = useState(0)
const onClick = () => setCount(count + 1)

useEffectDebounce(
  () => {
    console.log("count changed!")
  },
  [count],
  {
    maxWait: 1000, // 1s in ms
  }
)

Type Declaration

import { const useEffectDebounce: (callback: () => void, deps: unknown[] | undefined, options?: UseEffectDebounceOptions) => voiduseEffectDebounce } from "@kaioken-core/hooks"

function useEffectDebounce(callback: () => void, deps: unknown[] | undefined, options?: UseEffectDebounceOptions): voiduseEffectDebounce(() => {}, [], {
  maxWait?: number | undefinedmaxWait: 0,
})