Skip to content

Commit

Permalink
Merge pull request #23804 from sookmax/fix-undefined-addon-state
Browse files Browse the repository at this point in the history
Manager API: Fix `api.getAddonState`default value
  • Loading branch information
kasperpeulen authored Aug 23, 2023
2 parents fd9aa21 + 503b18c commit 1c465ce
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions code/lib/manager-api/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,13 @@ export function useSharedState<S>(stateId: string, defaultState?: S) {
addonStateCache[stateId] ? addonStateCache[stateId] : defaultState
);

if (api.getAddonState(stateId) && api.getAddonState(stateId) !== state) {
api.setAddonState<S>(stateId, state).then((s) => {
addonStateCache[stateId] = s;
});
}
useEffect(() => {
if (api.getAddonState(stateId) === undefined && api.getAddonState(stateId) !== state) {
api.setAddonState<S>(stateId, state).then((s) => {
addonStateCache[stateId] = s;
});
}
}, [api]);

const setState = (s: S | API_StateMerger<S>, options?: Options) => {
const result = api.setAddonState<S>(stateId, s, options);
Expand Down

0 comments on commit 1c465ce

Please sign in to comment.