Skip to content

Wondering if we can gets some docs or recommendations on when to use computed with pinia getters #1426

Discussion options

You must be logged in to vote

You can actually make it much simpler, you don't need any wrapping at all. The only thing you can't do is destructure state or getters (const { validFamilyId } = useFamilyStore() -> not reactive):

<script setup>
const familyStore = useFamilyStore()

function doStuff() {
  familyStore.validFamilyId // read it directly
}

// or use storeToRefs() from pinia
const { validFamilyId } = storeToRefs(familyStore)
</script>

<template>
{{ familyStore.validFamilyId }}
</template>

BTW don't prefix getters with get unless they are returning a function and are meant to be called like store.getValidFamilyId(...), it makes more sense semantically.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants