Pinia · PINIA0005
Destructure store state and getters through storeToRefs()
Report state and getters destructured straight from a Pinia store during setup when the captured value can go stale.
Run this rule
pnpm vite-doctor . --rules pinia/state/no-store-destructure
Why it matters
Destructuring reads the store property once. Replacing it leaves the local holding the previous value. In-place changes to a reactive object still reach readers of its properties. A getter that returns a function without reading reactive state can keep reading state when the function is called.
Recommended fix
Destructure state and getters from storeToRefs(store), which returns a ref for each of them, and keep destructuring actions from the store itself. Or read store.key where the value is used.
Useful links
Example
Extract state and getters with storeToRefs()
Before
<script setup lang="ts">
const store = useCounterStore()
const { count, doubleCount, increment } = store
</script>
After
<script setup lang="ts">
import { storeToRefs } from 'pinia'
const store = useCounterStore()
const { count, doubleCount } = storeToRefs(store)
const { increment } = store
</script>