
Every Vue application that grows reaches a point where data no longer fits inside a single component: the signed-in user, the shopping cart, list filters, notifications. That is when you need one central place for state. At Inspire Web we use Pinia for this: the library recommended by the Vue team itself, which has replaced Vuex in new projects.
Why Pinia instead of Vuex
Pinia keeps the same philosophy but removes the ceremony. There are no separate mutations, no nested modules, and TypeScript support feels natural without extra type declarations. Each store is a small, self-contained file, which makes the code easier for a team to read and maintain.
A store in ten lines
With the “setup” style, a store looks exactly like a component that uses the Composition API:
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export const useCartStore = defineStore('cart', () => {
const items = ref([])
const total = computed(() => items.value.reduce((s, i) => s + i.price * i.qty, 0))
function add(product) { items.value.push({ ...product, qty: 1 }) }
return { items, total, add }
})A ref becomes state, a computed becomes a getter, and a function becomes an action. Nobody has to learn a second mental model.
What goes in a store and what does not
The most common mistake is putting everything into Pinia. The rule we follow:
- In a store: data needed by many unrelated components (user, permissions, cart, settings).
- Local to the component: form state, an open modal, the value of a search field.
- In a composable: reusable logic that does not need to share one instance of the data.
Practices that prevent problems
- One store per functional domain. A giant “appStore” quickly becomes the new global state, with all its problems.
- Use
storeToRefswhen you destructure state or getters, so reactivity is preserved. Actions can be destructured normally. - Keep API calls in actions (or in a separate service layer), so components stay simple and easy to test.
- Test with fresh stores. Creating a new
createPinia()for each test means every test starts from a clean state. - Persist sparingly. Save to
localStorageonly what truly needs to survive a refresh, and never sensitive data or tokens without careful thought.
Tooling and productivity
Integration with Vue Devtools gives you visibility into every store: you can see the state, its changes over time, and which action caused what. In SSR applications, for example with Nuxt, Pinia integrates without extra setup, which helps when the same project also has SEO requirements.
When you do not need it
In a small application or a simple website, provide/inject or a shared composable is often enough. The right architectural question is not “which library is popular”, but “how many parts of the application share this data, and how often does it change”.
Building an application with Vue?
Inspire Web designs and develops web applications and SaaS products with Vue.js, Spring Boot and modern, scalable architectures. If you would like us to look at your idea or review an existing application, get in touch.




