New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pinia-plugin-persistedstate

Package Overview
Dependencies
Maintainers
0
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinia-plugin-persistedstate

Configurable persistence and rehydration of Pinia stores.

  • 4.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
224K
increased by2.65%
Maintainers
0
Weekly downloads
 
Created

What is pinia-plugin-persistedstate?

The pinia-plugin-persistedstate npm package is a plugin for Pinia, a state management library for Vue.js. This plugin allows you to persist and rehydrate the state of your Pinia stores using various storage mechanisms like localStorage, sessionStorage, or custom storage solutions.

What are pinia-plugin-persistedstate's main functionalities?

Persist State to localStorage

This feature allows you to persist the state of your Pinia store to localStorage. By setting `persist: true` in your store definition, the state will be automatically saved to localStorage and rehydrated when the application is reloaded.

{"import":"import { createPinia } from 'pinia';\nimport piniaPluginPersistedstate from 'pinia-plugin-persistedstate';\n\nconst pinia = createPinia();\npinia.use(piniaPluginPersistedstate);","store":"import { defineStore } from 'pinia';\n\nexport const useMainStore = defineStore('main', {\n  state: () => ({\n    counter: 0\n  }),\n  persist: true\n});"}

Custom Storage

This feature allows you to use a custom storage mechanism for persisting the state. In this example, the state is persisted to sessionStorage instead of localStorage by providing a custom storage object.

{"import":"import { createPinia } from 'pinia';\nimport piniaPluginPersistedstate from 'pinia-plugin-persistedstate';\n\nconst pinia = createPinia();\npinia.use(piniaPluginPersistedstate);","store":"import { defineStore } from 'pinia';\n\nconst customStorage = {\n  getItem: (key) => window.sessionStorage.getItem(key),\n  setItem: (key, value) => window.sessionStorage.setItem(key, value),\n  removeItem: (key) => window.sessionStorage.removeItem(key)\n};\n\nexport const useMainStore = defineStore('main', {\n  state: () => ({\n    counter: 0\n  }),\n  persist: {\n    storage: customStorage\n  }\n});"}

Partial State Persistence

This feature allows you to persist only specific parts of the state. In this example, only the `counter` state is persisted, while the `user` state is not.

{"import":"import { createPinia } from 'pinia';\nimport piniaPluginPersistedstate from 'pinia-plugin-persistedstate';\n\nconst pinia = createPinia();\npinia.use(piniaPluginPersistedstate);","store":"import { defineStore } from 'pinia';\n\nexport const useMainStore = defineStore('main', {\n  state: () => ({\n    counter: 0,\n    user: {\n      name: '',\n      email: ''\n    }\n  }),\n  persist: {\n    paths: ['counter']\n  }\n});"}

Other packages similar to pinia-plugin-persistedstate

Keywords

FAQs

Package last updated on 16 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc