@@ -51,5 +51,44 @@ persistStore(
51
51
},
52
52
)
53
53
)
54
+ ` ` `
55
+
56
+ ## migration from previous storage
57
+
58
+ **tested with redux-persist v4**
54
59
60
+ the snippet below lets you migrate redux data previously stored in
61
+ ` AsyncStorage` to ` redux- persist- filesystem- storage` .
62
+
63
+ **NOTE** This snippet lets you migrate healthy data. It will not _restore_
64
+ data if it is already hit limits of ` AsyncStorage`
65
+
66
+ ` ` ` javascript
67
+ import { persistStore , getStoredState } from ' redux-persist'
68
+ import FilesystemStorage from ' redux-persist-filesystem-storage'
69
+ import { AsyncStorage } from ' react-native'
70
+ import _ from ' lodash'
71
+ import { createStore } from ' redux'
72
+
73
+ const store = createStore (... )
74
+
75
+ // create persistor for `redux-persist-filesystem-storage`
76
+ const fsPersistor = persistStore (
77
+ store,
78
+ { storage: FilesystemStorage },
79
+ async (fsError , fsResult ) => {
80
+ if (_ .isEmpty (fsResult)) {
81
+ // if state from fs storage is empty try to read state from previous storage
82
+ try {
83
+ const asyncState = await getStoredState ({ storage: AsyncStorage })
84
+ if (! _ .isEmpty (asyncState)) {
85
+ // if data exists in `AsyncStorage` - rehydrate fs persistor with it
86
+ fsPersistor .rehydrate (asyncState, { serial: false })
87
+ }
88
+ } catch (getStateError) {
89
+ console .warn (" getStoredState error" , getStateError)
90
+ }
91
+ }
92
+ }
93
+ )
55
94
` ` `
0 commit comments