From 0fbce9f857a8951f32b6a182b819fecb41fd15a5 Mon Sep 17 00:00:00 2001 From: peternandersson Date: Fri, 23 May 2025 15:29:26 -0700 Subject: [PATCH] better fix --- src/react/hooks.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/react/hooks.ts b/src/react/hooks.ts index f539ca5..7981771 100644 --- a/src/react/hooks.ts +++ b/src/react/hooks.ts @@ -163,11 +163,15 @@ export function useVariable( id: string, ): [WorkbookVariable | undefined, Function] { const client = usePlugin(); - const [workbookVariable, setWorkbookVariable] = useState( - client.config.getVariable(id), - ); + const [workbookVariable, setWorkbookVariable] = useState(); + + const isFirstRender = useRef(true); useEffect(() => { + if (isFirstRender.current) { + setWorkbookVariable(client.config.getVariable(id)); + isFirstRender.current = false; + } return client.config.subscribeToWorkbookVariable(id, setWorkbookVariable); }, [client, id]);