Skip to content

@pinia/root / pinia / defineStore

defineStore()

Call Signature

ts
function defineStore<Id, S, G, A>(id, options): StoreDefinition<Id, S, G, A>;

Creates a useStore function that retrieves the store instance

Type Parameters

Id

Id extends string

S

S extends StateTree = { }

G

G extends _GettersTree<S> = { }

A

A = { }

Parameters

id

Id

id of the store (must be unique)

options

Omit<DefineStoreOptions<Id, S, G, A>, "id">

options to define the store

Returns

StoreDefinition<Id, S, G, A>

Call Signature

ts
function defineStore<Id, SS>(
   id, 
   storeSetup, 
options?): StoreDefinition<Id, _ExtractStateFromSetupStore<SS>, _ExtractGettersFromSetupStore<SS>, _ExtractActionsFromSetupStore<SS>>;

Creates a useStore function that retrieves the store instance

Type Parameters

Id

Id extends string

SS

SS

Parameters

id

Id

id of the store (must be unique)

storeSetup

(helpers) => SS

function that defines the store

options?

DefineSetupStoreOptions<Id, _ExtractStateFromSetupStore<SS>, _ExtractGettersFromSetupStore<SS>, _ExtractActionsFromSetupStore<SS>>

extra options

Returns

StoreDefinition<Id, _ExtractStateFromSetupStore<SS>, _ExtractGettersFromSetupStore<SS>, _ExtractActionsFromSetupStore<SS>>

Released under the MIT License.