Configurable persistence and rehydration of Pinia stores.
The Pinia Plugin PersistedState is a tool that allows users to persist Pinia stores with a user-friendly API. It is highly customizable and compatible with various frameworks. Additionally, it is a lightweight package with no external dependencies, making it an efficient and convenient choice for developers.
To install the Pinia Plugin PersistedState, follow these steps:
Install the plugin using your preferred package manager:
pnpm i pinia-plugin-persistedstate
npm i pinia-plugin-persistedstate
yarn add pinia-plugin-persistedstate
Add the plugin to your Pinia configuration.
Define the persist
option for the store you want to persist.
// Add the plugin to Pinia
import { createPinia } from 'pinia';
import { persist } from 'pinia-plugin-persistedstate';
const pinia = createPinia();
pinia.use(persist);
// Define persist options for a store
pinia.persist({
store: yourStore,
key: 'yourStoreKey',
storage: localStorage
});
For detailed configuration options, please refer to the official documentation.
The Pinia Plugin PersistedState is a powerful tool for persisting Pinia stores with a user-friendly API. It offers customization options, compatibility with various frameworks, and a lightweight package size. By using this plugin, developers can easily persist Pinia stores and enhance the efficiency of their applications.