fix websocket from spreading stale state

This commit is contained in:
Josh Hawkins 2024-10-20 21:03:08 -05:00
parent 6c70e56059
commit a8f8666334

View File

@ -65,7 +65,10 @@ function useValue(): useValueReturn {
: "OFF";
});
setWsState({ ...wsState, ...cameraStates });
setWsState((prevState) => ({
...prevState,
...cameraStates,
}));
setHasCameraState(true);
// we only want this to run initially when the config is loaded
// eslint-disable-next-line react-hooks/exhaustive-deps
@ -77,7 +80,10 @@ function useValue(): useValueReturn {
const data: Update = JSON.parse(event.data);
if (data) {
setWsState({ ...wsState, [data.topic]: data.payload });
setWsState((prevState) => ({
...prevState,
[data.topic]: data.payload,
}));
}
},
onOpen: () => {