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

    Function useInterval

    • A replacement for window.setInterval that schedules a function to be called repeatedly with a fixed delay between executions. The interval is cancelled when the component is unmounted or when a new interval is scheduled.

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

      Intervals must be scheduled or cancelled after the component has mounted. Before that, calling either function is a no-op.

      Returns [schedule: Schedule, cancel: () => void]

      const [schedule, cancel] = useInterval();

      useEffect(() => {
      // Cancels the currently scheduled callback and schedules a new one
      schedule(
      (a, b) => {
      doSomething(a, b);
      },
      500, // Interval delay
      a, b, // Arguments passed to the callback
      );

      // Stops invoking the callback that was last provided to schedule()
      cancel();
      }, []);