Vue.js Developer interview question · Most asked
Pinia or Vuex: what is the difference, and why is Pinia now recommended?
Summary
Pinia is the official state management library for Vue 3 (Vuex is in maintenance mode). It drops mutations (actions can change state directly), has a simpler API, first-class TypeScript inference, modular stores by default instead of nested modules, and Devtools support including time travel.
Longer Answer
A Pinia store can be written in options style (state, getters, actions) or setup style (a function using refs and computed, like a composable). Stores are created lazily when first used, which works well with code splitting. For SSR, state is per request (no module-level singletons leaking between users) and serialised for hydration.
Not everything belongs in a store: keep local UI state in components and server data in a data-fetching layer when possible.
Key Points
- Official store for Vue 3; Vuex in maintenance.
- No mutations; simpler API.
- Excellent TypeScript support.
- Options or setup style stores.
More most-asked Vue.js Developer questions
- Options API or Composition API: what is the difference, and which would you use?
- How do props work, and what is one-way data flow?
- How does Vue 3's reactivity system work, and how does it differ from Vue 2's?
- computed, watch or watchEffect: when do you use each?
- ref or reactive: what is the difference, and when do you use each?
- How do you use Vue Router: dynamic routes, nested routes and navigation guards?
- Why does v-for need a key, and why should it not be the index?
- What are composables, and why did they replace mixins?