Improved structure and added caching for server messages

This commit is contained in:
2025-10-15 22:14:14 +02:00
parent 35ecc51098
commit 54194298ab
4 changed files with 89 additions and 13 deletions
+18
View File
@@ -0,0 +1,18 @@
import { useEffect, useRef } from "react";
export function useEffectOnceWhenReady(
effect: () => void,
deps: any[],
testers: (undefined | ((m: any) => boolean))[]
) {
const hasRun = useRef(false);
useEffect(() => {
const allReady = deps.every(
(d, i) => d !== undefined && d !== null && (!testers[i] || testers[i](d))
);
if (!allReady || hasRun.current) return;
hasRun.current = true;
effect();
}, deps);
}