How to map state using composition API? #1307
-
With Vuex, it was possible to map state inside of a component but how can I do the same thing with Pina and composition API? I see there is For example, with Vuex it was possibe to map state like this:
What would be a Pinia / Composition API equivalent? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You could just use a computed: const settings = useSettingsStore()
// other computed
const logoSrc = computed(() => settings.settings.designSettings.logo) |
Beta Was this translation helpful? Give feedback.
-
Hi, mapping state with e.g // store.ts
export const useStore = defineStore('store', () => {
const state = ref(false);
const mappedState = computed({
get() {
return state.value;
},
set(value: boolean) {
state.value = value;
},
});
return {
mappedState,
};
});
// component.vue
const store = useStore()
const state = computed(() => store.mappedState) // e.g. state = true appears to not be working I don't know if this is the intended behavior, and I know I can probably just rewrite the component's EDIT: actually, using a get/set computed in the store is not even the designed behavior for a GETter, my bad |
Beta Was this translation helpful? Give feedback.
You could just use a computed: