Skip to content
Source
Sign inSign up
TanStack/store

feat: add state persistence support #246

Closedahmdtalat(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/246/headopened

Showing 2 changed files with 123 additions and 1 deletion (loading 1).

x
0 of 2 viewed, 2 left
123 additions and 1 deletionpackages/store/src/store.tsModified
View file
@@ -2,6 +2,31 @@
import { isUpdaterFunction } from './types'
import type { AnyUpdater, Listener, Updater } from './types'
​
+export interface Storage {
+ removeItem: (key: string) => void
+ getItem: (key: string) => string | null
+ setItem: (key: string, value: string) => void
+}
+​
+export interface PersistOptions<TState> {
+ /**
+ * Storage key to use when persisting state
+ */
+ key: string
+ /**
+ * Storage to use for persistence. Defaults to localStorage
+ */
+ storage?: Storage
+ /**
+ * Custom serializer. Defaults to JSON.stringify
+ */
+ serialize?: (state: TState) => string
+ /**
+ * Custom deserializer. Defaults to JSON.parse
+ */
+ deserialize?: (serializedState: string) => TState
+}
+​
export interface StoreOptions<