redux-persist
redux-persist copied to clipboard
State not retaining when the App reload/Kill the App from Background
I am using redux for maintaining the state in my App, Currently i am having issue in Android OS,
I am using the below dependencies
"@react-native-community/async-storage": "^1.6.1",
"react-redux": "^6.0.1",
"redux": "^4.0.2",
"redux-logger": "^3.0.6",
"redux-persist": "6.0.0",
"redux-thunk": "^2.3.0",
"rn-fetch-blob": "0.10.14"
"react-native": "^0.60.5",
"react": "16.8.6",
"react-apollo": "^2.1.11",
Below is my Redux configurations
const persistConfig = {
key: 'root',
keyPrefix: '',
storage: AsyncStorage,
};
const persistedReducer = persistReducer(persistConfig, reducer);
const store = createStore(persistedReducer, applyMiddleware(thunk));
const persistor = persistStore(store);
The issue i am facing is the data is saved in state when the app is active, If i am killing the app or app hot reload the app i am not getting the data saved in the state.
I tried to see the db file in terminal using the below comand
adb -d shell "run-as com.appid ls /data/data/com.appid/databases/
It is not showing any list, What might be the problem? Can anyone suggest
+1
Lets see what your reducer looks like
I have the same problem, any solution you found? It only happens to me on Android, In ios it works perfectly
I tried to see the db file in terminal using the below comand
adb -d shell "run-as com.appid ls /data/data/com.appid/databases/
Your data stored not in database. It is stored in AsyncStorage
@whalemare AsyncStorage uses a database
On iOS, AsyncStorage is backed by native code that stores small values in a serialized dictionary and larger values in separate files. On Android, AsyncStorage will use either RocksDB or SQLite based on what is available.
I'm seeing this problem in the wild too and it seems to be related to large store states. How big is your store? We also have nested persist configs and combined reducers so I'm not sure if that is affecting the issue.
I had this issue too, i recommend you to check the data that you save and to save it as little as possible.
This happens because of using setInterval
to throttle the update in createPersistoid.js
, the problem is that setInterval
gets paused whenever the app goes to background.
It is not relevant to the size of the object in that case, manually calling flush()
will save the data
When your store is large (>4 Mb) you're more likely to run out of memory on Android.
To see the size of your store, you can execute showAsyncStorageContentInDev()
on your RN debugger console, and it'll return your current store as a jsonified object, with size and all.
If this is your case, then see #199. Fortunately there are some libraries specifically designed to solve this issue, such as redux-persist-filesystem-storage, so be sure to check them out.
having the same problem in 2023, version 6.0.0, any solutions?
Same problem, any solution ?
any solutions???
I do have the same issue, but not using async storage, I'm using file based redux-persist-filesystem-storage. In my case, by analysing the React Native bridge, I can see that it's pretty busy parsing and saving files. I'm still using the original (old) RN architecture, so the bridge still slowing it down. Is any of you using the RN new architecture and still having the issue? Thanks.
same here also