Skip to content

@pinia/root / pinia / mapWritableState

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

Call Signature ​

ts
function mapWritableState<Id, S, G, A, KeyMapper>(useStore, keyMapper): _MapWritableStateObjectReturn<S, G, 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

• A

• KeyMapper extends Record<string, _MapWritableStateKeys<S, G>>

Parameters ​

useStore ​

StoreDefinition<Id, S, G, A>

store to map from

keyMapper ​

KeyMapper

object of state properties

Returns ​

_MapWritableStateObjectReturn<S, G, KeyMapper>

Param ​

store to map from

Param ​

array or object

Call Signature ​

ts
function mapWritableState<Id, S, G, A, Keys>(useStore, keys): Pick<_MapWritableStateReturn<S, G, Keys>, Keys>

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

• 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 ​

Pick<_MapWritableStateReturn<S, G, Keys>, Keys>

Param ​

store to map from

Param ​

array or object

Released under the MIT License.