mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-10-23 18:56:29 +02:00
14 lines
349 B
TypeScript
14 lines
349 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
const useInterval = (callback: () => void, delay?: number) => {
|
|
useEffect(() => {
|
|
const handler = () => callback();
|
|
if (delay !== null) {
|
|
const id = setInterval(handler, delay);
|
|
return () => clearInterval(id);
|
|
}
|
|
}, [delay]);
|
|
};
|
|
|
|
export default useInterval;
|