Features
- Reactive refs that sync with storage
- localStorage, sessionStorage, and memory adapters
- Custom serialization support
- SSR fallback to memory adapter
- Automatic cleanup on remove/clear
- Cross-tab synchronization (localStorage only)
Installation
Basic Usage
API Reference
createStoragePlugin()
Creates a storage plugin.Plugin configuration
The storage adapter to useDefaults to
localStorage in browser, MemoryAdapter in SSR.Built-in adapters:window.localStoragewindow.sessionStoragenew MemoryAdapter()(for SSR)
The prefix to use for all storage keysExample: With prefix
'app:', key 'user' becomes 'app:user' in storage.Custom serializer for reading and writing valuesDefaults to
JSON.parse / JSON.stringify.Example:The namespace for the storage context
StorageContext
Check if a key exists in the cacheNote: This checks the in-memory cache, not the storage adapter directly.Example:
Get a reactive ref for a storage keyIf the key doesn’t exist in cache, reads from storage adapter and caches it.
Returns the same ref instance for subsequent calls with the same key.Examples:
Set a value for a storage keyCreates a ref if it doesn’t exist, updates existing ref otherwise.Example:
Remove a key from storageStops the watcher, removes from cache, and deletes from storage adapter.Example:
Clear all keys from storageStops all watchers, clears cache, and removes all prefixed keys from storage adapter.Example:
Storage Adapters
localStorage (Default in Browser)
sessionStorage
Memory (Default in SSR)
Custom Adapter
Examples
User Preferences
Shopping Cart
Form Draft Auto-Save
Null/Undefined Removal
Cross-Tab Synchronization
When usinglocalStorage, changes are automatically synchronized across tabs: