@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
26 lines (22 loc) • 655 B
JavaScript
"use client";
import { useCallbackRef } from "../../utils/ref.js";
import { useEffect } from "react";
//#region src/hooks/use-interval/index.ts
/**
* `useInterval` is a custom hook that runs a function at a specified interval.
*
* @see https://yamada-ui.com/docs/hooks/use-interval
*/
const useInterval = (callback, delay) => {
const callbackRef = useCallbackRef(callback);
useEffect(() => {
let timeoutId = null;
if (delay !== null) timeoutId = setInterval(callbackRef, delay);
return () => {
if (timeoutId) clearInterval(timeoutId);
};
}, [delay, callbackRef]);
};
//#endregion
export { useInterval };
//# sourceMappingURL=index.js.map