From b1e0267c7f997fcdbdef7032d97c4f3be616f40c Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 1 Nov 2024 10:16:22 +0100 Subject: [PATCH] Daten von Server alle 10 Sekunden holen und aktualisieren in dashboard.js, setInterval ist in _app.js --- pages/_app.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pages/_app.js b/pages/_app.js index 35e6ba1..d085ae2 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -13,11 +13,17 @@ function MyApp({ Component, pageProps }) { useEffect(() => { const loadAndStoreVariables = async () => { const variables = await loadWindowVariables(); - store.dispatch(setVariables(variables)); // Speichere die geladenen Variablen im Redux Store + store.dispatch(setVariables(variables)); }; if (typeof window !== "undefined") { - loadAndStoreVariables(); + loadAndStoreVariables(); // Initial load + + // Interval for updating the Redux store every 10 seconds + const intervalId = setInterval(loadAndStoreVariables, 10000); + + // Cleanup interval when component unmounts + return () => clearInterval(intervalId); } }, []);