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

← All Vue.js Developer questions