PersistedState
A reactive state manager that persists and synchronizes state across browser sessions and tabs using Web Storage APIs.
PersistedState
provides a reactive state container that automatically persists data to browser
storage and optionally synchronizes changes across browser tabs in real-time.
Demo
Count: 0
Note
You can refresh this page and/or open it in another tab to see the count state being persisted
and synchronized across sessions and tabs.
Usage
Initialize PersistedState
by providing a unique key and an initial value for the state.
Configuration Options
PersistedState
includes an options
object that allows you to customize the behavior of the state
manager.
Storage Options
'local'
: Data persists until explicitly cleared'session'
: Data persists until the browser session ends
Cross-Tab Synchronization
When syncTabs
is enabled (default), changes are automatically synchronized across all browser tabs
using the storage event.
Custom Serialization
Provide custom serialize
and deserialize
functions to handle complex data types: