0
0
Vueframework~20 mins

Pinia vs Vuex comparison - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pinia vs Vuex Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Key difference in store setup between Pinia and Vuex
Which statement correctly describes how you create a store in Pinia compared to Vuex?
APinia requires manual mutation definitions, Vuex automatically infers mutations.
BVuex stores are created with functions, Pinia uses plain objects only.
CBoth Pinia and Vuex require class-based stores to manage state.
DPinia uses a function to define stores, while Vuex uses an object with mutations and actions.
Attempts:
2 left
💡 Hint
Think about how you define state and actions in each library.
component_behavior
intermediate
2:00remaining
State reactivity difference in Pinia vs Vuex
What happens when you update a state property in Pinia compared to Vuex in a Vue component?
APinia state updates are reactive and reflected immediately; Vuex requires committing mutations to update state reactively.
BNeither Pinia nor Vuex support reactive state updates in Vue components.
CVuex state updates automatically trigger reactivity; Pinia requires explicit mutation commits.
DBoth Pinia and Vuex require manual DOM updates after state changes.
Attempts:
2 left
💡 Hint
Consider how each library handles state changes and reactivity.
📝 Syntax
advanced
2:30remaining
Correct syntax for defining a Pinia store
Which code snippet correctly defines a Pinia store with a state property 'count' initialized to 0 and an action 'increment' that increases count by 1?
A
import { defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  actions: {
    increment() {
      this.count++;
    }
  }
});
B
import { createStore } from 'pinia';
export const useCounterStore = createStore({
  count: 0,
  increment() {
    this.count++;
  }
});
C
import { defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', () => {
  const count = 0;
  function increment() {
    count++;
  }
  return { count, increment };
});
D
import { defineStore } from 'pinia';
export const useCounterStore = defineStore({
  state: { count: 0 },
  actions: {
    increment() {
      this.count++;
    }
  }
});
Attempts:
2 left
💡 Hint
Check the correct function and object structure for Pinia stores.
🔧 Debug
advanced
2:00remaining
Identify the error in Vuex mutation usage
Given this Vuex mutation code, what error will occur when committing 'increment' mutation? const store = new Vuex.Store({ state: { count: 0 }, mutations: { increment(state) { state.count += 1 } } }); store.commit('increment'); console.log(store.state.count);
ATypeError because 'state' is undefined in mutation.
BNo error; output will be 1.
CSyntaxError due to missing semicolon in mutation.
DRuntime error because mutations cannot modify state directly.
Attempts:
2 left
💡 Hint
Check how Vuex mutations receive state and how commit works.
state_output
expert
2:30remaining
Pinia store state after multiple actions
Consider this Pinia store and usage: import { defineStore } from 'pinia'; export const useStore = defineStore('main', { state: () => ({ value: 10 }), actions: { add(n) { this.value += n; }, reset() { this.value = 0; } } }); const store = useStore(); store.add(5); store.add(-3); store.reset(); store.add(7); What is the final value of store.value?
A0
B19
C7
D15
Attempts:
2 left
💡 Hint
Follow each action step by step and update the value.