Challenge - 5 Problems
Pinia Store Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the initial state of this Pinia store?
Given the Pinia store below, what is the value of
count when the store is first used in a component?Vue
import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => ({ count: 10 }), actions: { increment() { this.count++ } } })
Attempts:
2 left
💡 Hint
Look at the
state function's returned object.✗ Incorrect
The
state function returns an object with count set to 10, so the initial value is 10.📝 Syntax
intermediate2:00remaining
Which option correctly defines a Pinia store with a getter?
Select the option that correctly defines a Pinia store with a getter named
doubleCount that returns count * 2.Attempts:
2 left
💡 Hint
Pinia getters receive state as the first argument and should not use
this.✗ Incorrect
In Pinia, getters receive the state as the first argument and should be arrow functions or functions using the state parameter. Using
this inside getters is not recommended.🔧 Debug
advanced2:00remaining
Why does this Pinia store action not update the state?
Consider this Pinia store code. Why does calling
increment() not change count?Vue
import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => ({ count: 0 }), actions: { increment() { let count = this.count count++ } } })
Attempts:
2 left
💡 Hint
Look at what variable is being incremented inside the action.
✗ Incorrect
The action creates a local variable
count and increments it, but does not update this.count. The state remains unchanged.❓ state_output
advanced2:00remaining
What is the value of
fullName after calling setName('Alice', 'Smith')?Given this Pinia store, what is the value of
fullName after calling the action setName('Alice', 'Smith')?Vue
import { defineStore } from 'pinia' export const useUserStore = defineStore('user', { state: () => ({ firstName: '', lastName: '' }), getters: { fullName: (state) => `${state.firstName} ${state.lastName}` }, actions: { setName(first, last) { this.firstName = first this.lastName = last } } }) // Usage: const userStore = useUserStore() userStore.setName('Alice', 'Smith') const result = userStore.fullName
Attempts:
2 left
💡 Hint
Check how the getter combines firstName and lastName.
✗ Incorrect
The action sets firstName and lastName, and the getter returns them joined with a space.
🧠 Conceptual
expert2:00remaining
Why use
defineStore with an ID string in Pinia?What is the main reason Pinia requires an ID string when creating a store with
defineStore?Attempts:
2 left
💡 Hint
Think about how Pinia tracks and manages multiple stores.
✗ Incorrect
The ID string uniquely identifies the store instance for debugging tools and plugins like persistence.