A Vue component does not re-render when the Pinia store changes
The store value changes in Vue devtools but the template still shows the old valueShort answer
The store itself is reactive, but copies of its values are not. If you destructure state out of the store, replace $state, or add a property that was never declared in state, Vue has nothing to track. Read through the store or storeToRefs(), change state with $patch, and declare every property up front.
Fix it fast
1Find out which cause you have
Log the store property and the local variable your template uses, next to each other, after you trigger the change. If the store is right and the variable is stale, you copied the value.
const store = useCounterStore() console.log(store.count, count) // 'count' is the variable the template shows2Match what you see, then jump to its fix
- 1
const { count, name } = useCounterStore() in script setup, and the values never changeState was destructured out of the storeFix - 2
Code such as store.$state = newData, then the view does not followThe whole state object was replacedFix - 3
store.secondCount = 2 works in the console but no component ever reactsA property was never declared in stateFix
- 1
What does the error look like?
The store value changes in Vue devtools but the template still shows the old valueThe component updates only after a full page reload
Cause 1 of 3
State was destructured out of the store
1Check
Pinia's docs say a store is a reactive object, so destructuring it breaks reactivity: you get plain values, not live ones.
grep -rn --include=*.vue --include=*.ts -E "const \{[^}]+\} = use[A-Za-z]+Store\(" src/2Fix
Keep the store object and read from it, or use storeToRefs() for state and getters. Actions can be destructured directly because they are bound to the store.
import { storeToRefs } from 'pinia'
const store = useCounterStore()
const { count, doubleCount } = storeToRefs(store) // stays reactive
const { increment } = store // actions are safe3Verify
Trigger the action in the browser. The template now follows the store.
npm run devConfirmed by pinia.vuejs.org
Cause 2 of 3
The whole state object was replaced
1Check
The state page says you cannot replace the state of a store, because that would break reactivity.
grep -rn --include=*.vue --include=*.ts '\$state *=' src/2Fix
Update the existing state with $patch, which takes a partial object or a function.
store.$patch({ user: newUser, items: newItems })
// or for arrays:
store.$patch((state) => {
state.items.push(newItem)
})3Verify
Run the same action again and watch the component update.
npm run devConfirmed by pinia.vuejs.org
Cause 3 of 3
A property was never declared in state
1Check
Pinia's docs say properties missing from state() cannot be added later, and every piece of state must be declared, even with an initial value of undefined.
sed -n '1,40p' src/stores/counter.ts2Fix
Add the property to state with an initial value, then assign to it.
export const useCounterStore = defineStore('counter', {
state: () => ({
count: 0,
secondCount: undefined as number | undefined,
}),
})3Verify
Assign to the property again and check that the template updates.
npm run devConfirmed by pinia.vuejs.org
How do I stop it coming back?
- Use the store as store.x in templates and scripts, and reach for storeToRefs() when you want a short name.
- Declare every state property in the initial state, even if the value starts as undefined.
- Change state with actions or $patch instead of replacing objects the store owns.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fixWeb apps
A POST to a Google Apps Script web app returns 405 or a CORS error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.
3 causes, each with a fix