Daten von Server alle 10 Sekunden holen und aktualisieren in dashboard.js, setInterval ist in _app.js

This commit is contained in:
ISA
2024-11-01 10:16:22 +01:00
parent c6163ba54d
commit b1e0267c7f

View File

@@ -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);
}
}, []);