0.0.3 • Published 2 years ago

@mwjz/pinia-storage v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Persistence state in your pinia 🍍 store!

Installation

npm install @mwjz/pinia-storage

Usage

import { PiniaStorage } from '@mwjz/pinia-storage'

// Pass the plugin to your application's pinia plugin
pinia.use(PiniaStorage())

You can then use storage option in your stores:

defineStore('id', {
  state: () => ({ bar: '', baz: 0, foo: null }),
  storage: {
    local: ['bar'],
    session: {
      baz: {
        read: (baz) => Number(baz)
      },
      foo: {
        write: (foo: object) => JSON.stringify(foo),
        read: (foo) => {
          try {
            if (!foo) return null;
            return JSON.parse(foo);
          } catch (error) {
            return null
          }
        }
      },
    }
  }
})

License

MIT