Skip to content

Commit

Permalink
config should respond to stage changes
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Nov 12, 2024
1 parent 4672f93 commit 85cc048
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ui/stage/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAtomValue } from "jotai";
import { useState, useEffect } from "react";
import { useState, useEffect, useRef } from "react";
import { type SMXStage, type SMXSensorTestData, SensorTestMode } from "../../sdk";
import { displayTestData$ } from "../state";

Expand Down Expand Up @@ -48,8 +48,17 @@ export function useTestData(stage: SMXStage | undefined) {
}

export function useConfig(stage: SMXStage | undefined) {
const stageRef = useRef(stage);
const [configData, setConfig] = useState(stage?.config);

useEffect(() => {
if (stageRef.current !== stage) {
// detected the stage has changed, so keep the config in sync
setConfig(stage?.config);
stageRef.current = stage;
}
}, [stage]);

useEffect(() => {
return stage?.configResponse$.onValue((config) => setConfig(config.config));
}, [stage]);
Expand Down

0 comments on commit 85cc048

Please sign in to comment.