diff --git a/code/lib/manager-api/src/index.tsx b/code/lib/manager-api/src/index.tsx index 688b4a2d6837..ab247114e440 100644 --- a/code/lib/manager-api/src/index.tsx +++ b/code/lib/manager-api/src/index.tsx @@ -399,11 +399,13 @@ export function useSharedState(stateId: string, defaultState?: S) { addonStateCache[stateId] ? addonStateCache[stateId] : defaultState ); - if (api.getAddonState(stateId) && api.getAddonState(stateId) !== state) { - api.setAddonState(stateId, state).then((s) => { - addonStateCache[stateId] = s; - }); - } + useEffect(() => { + if (api.getAddonState(stateId) === undefined && api.getAddonState(stateId) !== state) { + api.setAddonState(stateId, state).then((s) => { + addonStateCache[stateId] = s; + }); + } + }, [api]); const setState = (s: S | API_StateMerger, options?: Options) => { const result = api.setAddonState(stateId, s, options);