useEffectThrottle

same as useEffect but will only be called once every maxWait in ms (defaults to 0ms)

Demo

Open console to see logs

count: 0

Usage

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

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

Type Declaration

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

function useEffectThrottle(callback: () => void, deps: unknown[] | undefined, options?: UseEffectThrottleOptions): voiduseEffectThrottle(() => {}, [], {
  maxWait?: number | undefinedmaxWait: 0,
})