React Hookers - v6.3.0
    Preparing search index...

    Function useIntervalCallback

    • Invokes a callback periodically while the component is mounted.

      All functions scheduled with the same delay are invoked synchronously across all components that use this hook.

      Type Parameters

      • A extends any[]

        The callback argument types.

      Parameters

      • cb: (...args: A) => void

        The callback to invoke.

      • ms: number

        The delay, in milliseconds, between invocations.

      • ...args: A

        Arguments passed to the callback.

      Returns void

      const [count, setCount] = useState(0);

      // Increment the counter every second while the component is mounted
      useIntervalCallback(
      step => setCount(prevCount => prevCount + step),
      1000, // Interval delay in milliseconds
      1 // Argument passed to the callback
      );