Skip to content

@pinia/root / pinia

pinia

Index

Enumerations

EnumerationDescription
MutationTypePossible types for SubscriptionCallback

Interfaces

InterfaceDescription
_StoreOnActionListenerContextActual type for StoreOnActionListenerContext. Exists for refactoring purposes. For internal use only. For internal use only
_StoreWithStateBase store with state and functions. Should not be used directly.
_SubscriptionCallbackMutationBaseBase type for the context passed to a subscription callback. Internal type.
DefineSetupStoreOptionsOptions parameter of defineStore() for setup stores. Can be extended to augment stores with the plugin API.
DefineStoreOptionsOptions parameter of defineStore() for option stores. Can be extended to augment stores with the plugin API.
DefineStoreOptionsBaseOptions passed to defineStore() that are common between option and setup stores. Extend this interface if you want to add custom options to both kinds of stores.
DefineStoreOptionsInPluginAvailable options when creating a pinia plugin.
MapStoresCustomizationInterface to allow customizing map helpers. Extend this interface with the following properties:
PiniaEvery application must own its own pinia to be able to create stores
PiniaCustomPropertiesInterface to be extended by the user when they add properties through plugins.
PiniaCustomStatePropertiesProperties that are added to every store.$state by pinia.use().
PiniaPluginPlugin to extend every store.
PiniaPluginContextContext argument passed to Pinia plugins.
SetupStoreDefinitionReturn type of defineStore() with a setup function. - Id is a string literal of the store's name - SS is the return type of the setup function
StoreDefinitionReturn type of defineStore(). Function that allows instantiating a store.
StorePropertiesProperties of a store.
SubscriptionCallbackMutationDirectContext passed to a subscription callback when directly mutating the state of a store with store.someState = newValue or store.$state.someState = newValue.
SubscriptionCallbackMutationPatchFunctionContext passed to a subscription callback when store.$patch() is called with a function.
SubscriptionCallbackMutationPatchObjectContext passed to a subscription callback when store.$patch() is called with an object.

Type Aliases

Type aliasDescription
_ActionsTreeType of an object of Actions. For internal usage only. For internal use only
_Awaited-
_DeepPartialRecursive Partial<T>. Used by ['$patch'].
_ExtractActionsFromSetupStoreFor internal use only
_ExtractActionsFromSetupStore_KeysType that enables refactoring through IDE. For internal use only
_ExtractGettersFromSetupStoreFor internal use only
_ExtractGettersFromSetupStore_KeysType that enables refactoring through IDE. For internal use only
_ExtractStateFromSetupStoreFor internal use only
_ExtractStateFromSetupStore_KeysType that enables refactoring through IDE. For internal use only
_GettersTreeType of an object of Getters that infers the argument. For internal usage only. For internal use only
_MapActionsObjectReturnFor internal use only
_MapActionsReturnFor internal use only
_MapStateObjectReturnFor internal use only
_MapStateReturnFor internal use only
_MapWritableStateObjectReturnFor internal use only
_MapWritableStateReturnFor internal use only
_MethodGeneric type for a function that can infer arguments and return type
_SpreadFor internal use only.
_StoreObjectFor internal use only.
_StoreWithActionsStore augmented for actions. For internal usage only. For internal use only
_StoreWithGettersStore augmented with getters. For internal usage only. For internal use only
_UnwrapAllType that enables refactoring through IDE. For internal use only
PiniaStorePluginPlugin to extend every store.
StateTreeGeneric state of a Store
StoreStore type to build a store.
StoreActionsExtract the actions of a store type. Works with both a Setup Store or an Options Store.
StoreGenericGeneric and type-unsafe version of Store. Doesn't fail on access with strings, making it much easier to write generic functions that do not care about the kind of store that is passed.
StoreGettersExtract the getters of a store type. Works with both a Setup Store or an Options Store.
StoreOnActionListenerArgument of store.$onAction()
StoreOnActionListenerContextContext object passed to callbacks of store.$onAction(context => {}) TODO: should have only the Id, the Store and Actions to generate the proper object
StoreStateExtract the state of a store type. Works with both a Setup Store or an Options Store. Note this unwraps refs.
SubscriptionCallbackCallback of a subscription
SubscriptionCallbackMutationContext object passed to a subscription callback.

Variables

VariableDescription
PiniaVuePluginVue 2 Plugin that must be installed for pinia to work. Note you don't need this plugin if you are using Nuxt.js. Use the buildModule instead: https://pinia.vuejs.org/ssr/nuxt.html.

Functions

FunctionDescription
acceptHMRUpdateCreates an accept function to pass to import.meta.hot in Vite applications.
createPiniaCreates a Pinia instance to be used by the application
defineStoreCreates a useStore function that retrieves the store instance
disposePiniaDispose a Pinia instance by stopping its effectScope and removing the state, plugins and stores. This is mostly useful in tests, with both a testing pinia or a regular pinia and in applications that use multiple pinia instances. Once disposed, the pinia instance cannot be used anymore.
getActivePiniaGet the currently active pinia if there is any.
mapActionsAllows directly using actions from your store without using the composition API (setup()) by generating an object to be spread in the methods field of a component.
mapGettersAlias for mapState(). You should use mapState() instead.
mapStateAllows using state and getters from one store without using the composition API (setup()) by generating an object to be spread in the computed field of a component.
mapStoresAllows using stores without the composition API (setup()) by generating an object to be spread in the computed field of a component. It accepts a list of store definitions.
mapWritableStateAllows using state and getters from one store without using the composition API (setup()) by generating an object to be spread in the computed field of a component.
setActivePiniaSets or unsets the active pinia. Used in SSR and internally when calling actions and getters
setMapStoreSuffixChanges the suffix added by mapStores(). Can be set to an empty string. Defaults to "Store". Make sure to extend the MapStoresCustomization interface if you are using TypeScript.
shouldHydrateReturns whether a value should be hydrated
skipHydrateTells Pinia to skip the hydration process of a given object. This is useful in setup stores (only) when you return a stateful object in the store but it isn't really state. e.g. returning a router instance in a setup store.
storeToRefsCreates an object of references with all the state, getters, and plugin-added state properties of the store. Similar to toRefs() but specifically designed for Pinia stores so methods and non reactive properties are completely ignored.

Released under the MIT License.