Pinia · State

PINIA0005Destructure 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.

Why it happens

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.

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.

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>

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --rules pinia/state/no-store-destructure
Copyright © 2026