@jswork/pinia-plugin-watch
v1.0.8
Published
The easiest way to watch for your Pinia State.
Downloads
13
Readme
pinia-plugin-watch
The easiest way to watch for your Pinia State.
installation
npm install @jswork/pinia-plugin-watch
usage
import PiniaPluginWatch from '@jswork/pinia-plugin-watch';
// ======== main.js ======
export function createApp() {
const app = createSSRApp(App);
const pinia = createPinia();
pinia.use(PiniaStateTree);
pinia.use(piniaPluginWatch);
//...
}
// ======== stores/auth.js ======
import { defineStore } from "pinia";
export default defineStore("auth", {
state: () => ({ profile: null, other: null }),
watch: {
profile: (newValue, oldValue) => {
if (newValue) console.log("profile changed", newValue);
else console.log("profile removed", oldValue);
},
},
});
license
Code released under the MIT license.