Complete the code to define a state property in a Pinia store.
import { defineStore } from 'pinia' export const useUserStore = defineStore('user', { state: () => ({ [1]: '' }) })
The state function returns an object with properties representing the store's state. Here, name is a state property.
Complete the code to initialize a numeric state property in a Pinia store.
import { defineStore } from 'pinia' export const useCounterStore = defineStore('counter', { state: () => ({ count: [1] }) })
The count state property should be a number starting at zero, so use 0 without quotes.
Fix the error in the state definition by completing the code correctly.
import { defineStore } from 'pinia' export const useTodoStore = defineStore('todo', { state: () => ([1]) })
The state function must return an object. Using { todos: [] } inside parentheses is correct.
Fill both blanks to define a Pinia store state with a string and an array.
import { defineStore } from 'pinia' export const useProfileStore = defineStore('profile', { state: () => ({ username: [1], hobbies: [2] }) })
The username is an empty string '' and hobbies is an empty array [] as initial state values.
Fill all three blanks to define a Pinia store state with a boolean, a number, and an object.
import { defineStore } from 'pinia' export const useSettingsStore = defineStore('settings', { state: () => ({ darkMode: [1], fontSize: [2], preferences: [3] }) })
The initial state sets darkMode to false, fontSize to 14, and preferences to an empty object {}.