Skip to content

Commit 1b83221

Browse files
[useVariable] More consistent fix for initialization logic (#26)
1 parent d42faf9 commit 1b83221

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/react/hooks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,15 @@ export function useVariable(
163163
id: string,
164164
): [WorkbookVariable | undefined, Function] {
165165
const client = usePlugin();
166-
const [workbookVariable, setWorkbookVariable] = useState<WorkbookVariable>(
167-
client.config.getVariable(id),
168-
);
166+
const [workbookVariable, setWorkbookVariable] = useState<WorkbookVariable>();
167+
168+
const isFirstRender = useRef<boolean>(true);
169169

170170
useEffect(() => {
171+
if (isFirstRender.current) {
172+
setWorkbookVariable(client.config.getVariable(id));
173+
isFirstRender.current = false;
174+
}
171175
return client.config.subscribeToWorkbookVariable(id, setWorkbookVariable);
172176
}, [client, id]);
173177

0 commit comments

Comments
 (0)