The persistPlugin
is used to persist the state of a store in localStorage
. It ensures that the state of your store is maintained across page reloads by saving and rehydrating the state from storage.
The persistPlugin
takes an options object with the following properties:
key
(string, required
): The key used to store the state in localStorage
.properties
(array of keys, optional): A list of specific properties to persist. If not provided, all reactive properties will be persisted.The persistPlugin
works by saving the store state to localStorage
and rehydrating it on initialization. This allows the store to maintain its state between page reloads.
If an error occurs while parsing the saved state, the plugin will remove the corrupted item from localStorage
to prevent issues.
The plugin uses localStorage
to persist state, making it suitable for browser environments.
The plugin supports both reactive
and query-based
states, ensuring they are properly rehydrated.