use-interval

Wrapper around window.setInterval

Usage

Page loaded 0 seconds ago

API

const { start, stop, toggle, active } = useInterval(fn, interval);

Arguments:

  • fn – function that will be called at each interval tick
  • interval – amount of milliseconds between each tick

Return object:

  • start – start interval
  • stop – stop interval
  • toggle – toggle interval
  • active – current interval status

Definition

function useInterval(
  fn: () => void,
  interval: number
): {
  start: () => void;
  stop: () => void;
  toggle: () => void;
  active: boolean;
};