Optional
actionsOptional object of actions.
Optional
gettersOptional object of getters.
Unique string key to identify the store across the application.
Optional
stateFunction to create a fresh state. Must be an arrow function to ensure correct typings!
Optional
hydrateAllows hydrating the store during SSR when complex state (like client side only refs) are used in the store
definition and copying the value from pinia.state
isn't enough.
If in your state
, you use any customRef
s, any computed
s, or any ref
s that have a different value on
Server and Client, you need to manually hydrate them. e.g., a custom ref that is stored in the local
storage:
const useStore = defineStore('main', {
state: () => ({
n: useLocalStorage('key', 0)
}),
hydrate(storeState, initialState) {
// @ts-expect-error: https://github.com/microsoft/TypeScript/issues/43826
storeState.n = useLocalStorage('key', 0)
}
})
Generated using TypeDoc
Options parameter of
defineStore()
for option stores. Can be extended to augment stores with the plugin API.See
DefineStoreOptionsBase.