feat: quick connect

fixes #16
This commit is contained in:
Fredrik Burmester
2024-08-26 21:52:23 +02:00
parent 3047367ba6
commit e6d4414fd6
3 changed files with 137 additions and 12 deletions

19
hooks/useInterval.ts Normal file
View File

@@ -0,0 +1,19 @@
import { useEffect, useRef } from "react";
export function useInterval(callback: () => void, delay: number | null) {
const savedCallback = useRef<() => void>();
useEffect(() => {
savedCallback.current = callback;
}, [callback]);
useEffect(() => {
function tick() {
savedCallback.current?.();
}
if (delay !== null) {
const id = setInterval(tick, delay);
return () => clearInterval(id);
}
}, [delay]);
}