Question presented to candidate:
"Several unrelated parts of our Vue app need the same cart and user data, and props are getting passed five levels deep. What is Pinia, how does a store look, and why would you pick it over a plain reactive() object or Vuex?"
What a strong answer should cover:
- Pinia is the official state management library for Vue (the Vuex README now says "Pinia is now the new default"); a store is a reactive object shared by every component that calls
useXxxStore(). - The three parts: state, getters (cached, like
computed) and actions (methods, sync or async); both the option store and setup store syntaxes. - What it adds over a module-level
reactive(): devtools integration, SSR safety (one store set per request), plugins, HMR,$patch/$subscribe/$onAction, and a conventional structure. - What it removed compared with Vuex: no mutations, no nested modules or namespaces, full TypeScript inference without wrappers.
- Practical details:
app.use(createPinia()), destructure withstoreToRefs,$reset()exists only on option stores.
Clarifying questions expected:
- "Is this app server-rendered, or client-only?"
- "Is the shared data client state, or mostly server data that a query cache might handle better?"
Code / implementation expected: Yes β a small store (state, a getter, an action) and a component that uses it.