Skip to content

Commit

Permalink
fix: use proxy for useStore in Kirby 5
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 16, 2024
1 parent 9c9acec commit 5abf21c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/composables/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ interface PanelAppStore {
* @deprecated The Vuex store is removed in Kirby 5. Use the `useContent` composable instead.
*/
export function useStore() {
// `window.panel.app.$store` is not available in Kirby 5
const store = (usePanel() as any).app.$store as Readonly<PanelAppStore>;

if (!store) {
throw new Error(
"Vuex store is not available. Are you using Kirby 5? Use the `useContent` composable instead.",
);
return new Proxy({} as Readonly<PanelAppStore>, {
get() {
throw new Error(
"Vuex store is not available. Are you using Kirby 5? Use the `useContent` composable instead.",
);
},
});
}

return store;
Expand Down

0 comments on commit 5abf21c

Please sign in to comment.