Skip to content

API DocumentationDocs


API Documentation / pinia / mapWritableState

Function: mapWritableState()

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

Param

store to map from

Param

array or object

mapWritableState(useStore, keyMapper)

mapWritableState<Id, S, G, A, KeyMapper>(useStore, keyMapper): _MapWritableStateObjectReturn<S, KeyMapper>

Same as mapState() but creates computed setters as well so the state can be modified. Differently from mapState(), only state properties can be added.

Type Parameters

Id extends string

S extends StateTree

G extends _GettersTree<S>

A

KeyMapper extends Record<string, keyof S>

Parameters

useStore: StoreDefinition<Id, S, G, A>

store to map from

keyMapper: KeyMapper

object of state properties

Returns

_MapWritableStateObjectReturn<S, KeyMapper>

Param

store to map from

Param

array or object

mapWritableState(useStore, keys)

mapWritableState<Id, S, G, A, Keys>(useStore, keys): { [K in Keys]: Object }

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

Type Parameters

Id extends string

S extends StateTree

G extends _GettersTree<S>

A

Keys extends string | number | symbol

Parameters

useStore: StoreDefinition<Id, S, G, A>

store to map from

keys: readonly Keys[]

array of state properties

Returns

{ [K in Keys]: Object }

Param

store to map from

Param

array or object

Released under the MIT License.