useInterval

Custom hook that creates an interval that invokes a callback function at a specified delay using the [`setInterval API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval).

Custom hook that creates an interval that invokes a callback function at a specified delay using the setInterval API.

Usage

import { useInterval } from "@tilt-legal/cubitt-components/utilities/hooks";

const handleInterval = () => {
  // Code to be executed at each interval
};
useInterval(handleInterval, 1000);

API

Signature

declare function useInterval(callback: () => void, delay: number | null): void;

Parameters

ParameterTypeDescriptionDefault
callback() => voidThe function to be invoked at each interval.-
delay`numbernull`The time, in milliseconds, between each invocation of the callback. Use null to clear the interval.

Return Value

ValueTypeDescription
returnvoidValue returned by the hook.

On this page