Artwork from Pinia
pinia-plugin-autosetter
Auto Setter
⚙️ Installing
-
Install with your favorite package manager:
-
pnpm :
pnpm i pinia-plugin-autosetter
- npm :
npm i pinia-plugin-autosetter
- yarn :
yarn add pinia-plugin-autosetter
-
pnpm :
-
Add the plugin to pinia:
import { createPinia } from 'pinia'
import autoSetter from 'pinia-plugin-autosetter'
const pinia = createPinia()
pinia.use(autoSetter)
🚀 Usage
You just need to add the autosetter
option to the store you want to be automatically set the setter corresponding to State
as follows:
import { defineStore } from 'pinia'
//* using option store syntax
export const useCounterStore = defineStore('counter', {
state: () => {
return {
count: 0,
}
},
autosetter: true,
})
//* or using setup store syntax
export const useStore = defineStore(
'counter',
() => {
const count = ref(0)
return { count }
},
{
autosetter: true,
},
)
const counterStore = useCounterStore()
counterStore.setCount(10) // { count: 10 }
📝 License
Copyright © 2022 Chengbo Xie.
This project is under MIT license.