Hex Core JS
    Preparing search index...

    Function useInterval

    • Creates a setInterval function that works like window.setInterval, but subsequent calls clear the previous and cleanup on unmount is handled automatically. Also provides pauseInterval and resumeInterval functions for managing running intervals.

      Returns {
          clearInterval: () => void;
          pauseInterval: () => void;
          resumeInterval: () => void;
          setInterval: (handler: Function, timeout: number) => void;
      }

      Pausing an interval works differently from pausing a timeout. Instead of pausing the timer, the callback is disabled. Pausing an interval does not guarantee that after release the time until the next invocation is the remaining time in the period before pausing. For example, when running an interval with a delay of 1000ms, if the interval is paused 500ms into a period, then resumed after 1250ms, the time until next invocation would be 250ms rather than 500ms.