Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
'use client';
import { useState, useRef, useCallback, useEffect } from 'react';
function useInterval(fn, interval, { autoInvoke = false } = {}) {
const [active, setActive] = useState(false);
const intervalRef = useRef(null);
const fnRef = useRef(null);
const start = useCallback(() => {
setActive((old) => {
if (!old && (!intervalRef.current || intervalRef.current === -1)) {
intervalRef.current = window.setInterval(fnRef.current, interval);
}
return true;
});
}, []);
const stop = useCallback(() => {
setActive(false);
window.clearInterval(intervalRef.current || -1);
intervalRef.current = -1;
}, []);
const toggle = useCallback(() => {
if (active) {
stop();
} else {
start();
}
}, [active]);
useEffect(() => {
fnRef.current = fn;
active && start();
return stop;
}, [fn, active, interval]);
useEffect(() => {
if (autoInvoke) {
start();
}
}, []);
return { start, stop, toggle, active };
}
export { useInterval };
//# sourceMappingURL=use-interval.mjs.map

File diff suppressed because one or more lines are too long