@trashpanda001/helpers
    Preparing search index...

    Function useRafDebounce

    • Debounces a callback using requestAnimationFrame to sync with display refresh rate.

      This is ideal for high-frequency events like scroll, resize, or mousemove that need to update the UI. Instead of running on every event (which can be 1000+ times/sec), the callback runs at the display refresh rate (60fps/120fps).

      Type Parameters

      • T extends unknown[]

      Parameters

      • callback: (...args: T) => void

        Function to debounce

      Returns (...args: T) => void

      Debounced function that runs at display refresh rate

      const debouncedScroll = useRafDebounce(() => {
      updateScrollPosition()
      })

      window.addEventListener('scroll', debouncedScroll, { passive: true })
      window.removeEventListener('scroll', debouncedScroll)