A unique key to identify the store in storage.
The initial state of the store.
Optional
defineActions: null | DefineActions<TState, TActions> = nullA function to define actions for the store.
Optional
options: PersistentStoreOptions<TState> = {}Additional options for the persistent store.
The created store.
Creates a store that persists its state in local or session storage. Defaults to local storage but this can be changed in the options.
Note: The state needs to be serializable by whatever serializer you use. (JSON by default) If you need something more versatile I would recommend using a library like superjson.
Example
Basic usage:
Example
With superjson serialization and session storage: