API Documentation / pinia / DefineStoreOptionsInPlugin

Interface: DefineStoreOptionsInPlugin<Id, S, G, A>

pinia.DefineStoreOptionsInPlugin

Available options when creating a pinia plugin.

Type parameters

NameType
Idextends string
Sextends StateTree
GG
AA

Hierarchy

Properties

actions

actions: A

Extracted object of actions. Added by useStore() when the store is built using the setup API, otherwise uses the one passed to defineStore(). Defaults to an empty object if no actions are defined.

Defined in

pinia/src/types.ts:723


getters

Optional getters: G & ThisType<UnwrapRef<S> & _StoreWithGetters<G> & PiniaCustomProperties<string, StateTree, _GettersTree<StateTree>, _ActionsTree>> & _GettersTree<S>

Optional object of getters.

Inherited from

Omit.getters

Defined in

pinia/src/types.ts:647

Methods

hydrate

Optional hydrate(storeState, initialState): void

Allows 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.

example If in your state, you use any customRefs, any computeds, or any refs 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)
  }
})

Parameters

NameTypeDescription
storeStateUnwrapRef<S>the current state in the store
initialStateUnwrapRef<S>initialState

Returns

void

Inherited from

Omit.hydrate

Defined in

pinia/src/types.ts:687


state

Optional state(): S

Function to create a fresh state. Must be an arrow function to ensure correct typings!

Returns

S

Inherited from

Omit.state

Defined in

pinia/src/types.ts:642