pinia-use-persist

Easy to use persist plugin with configurable encryption, Currently in development, but already used in real production for simple scenarios
2,164
Install
npm install pinia-use-persist
Latest Version:0.0.21
Last Updated:Jun 23, 2022
Links: npm
Maintainer: sysabort

Documentation

Install

npm i pinia-use-persist

Use

main.ts


import {createPinia} from "pinia";

import {usePersist} from 'pinia-use-persist'

const pinia = createPinia()

pinia.use(usePersist)

app.use(pinia)

store.ts

export const useStore = defineStore('main', {
  state: () => ({
    counter: 0,
  }),
  persist:{
    enabled: true,
    key: ['counter'],
    encryptionKey: 'my-store',
    storage: sessionStorage,
  }
})

<script setup lang='ts'>
import { useStore } from '@/store/store.ts'
const store = useStore()

const add = () => {
  store.$patch((state) => {
    state.counter = state.counter + 1
  })
}
</script>

<template>
  <div>
    <p>{{store.$state.counter}}</p>
    <button @click="add">+</button>
  </div>
</template>

Note: 📢

When you add new key-value in store.ts file, you need to reload the page to achieve persistence.

Plan 📢

  1. Logger
  2. Encryption
  3. ...

Related Packages

pinia-persists

a pinia plugin for state persist.

792 16
pinia-plugin-store

pinia plugin store

15,186 10
pinia-plugin-unstorage

The best persistence plugin for pinia.

7,927
pinia-simple-persist

Simple pinia persistence without using $patch

1,346 0
pinia-plugin-persistedstate-2

Persist and rehydrate your Pinia state between page reloads

257,084 115

Version History

Version Released License
0.0.21
0.0.19
0.0.18
0.0.17
0.0.16
Pre-releases (1)
Version Released License
0.0.1-9.1