Reputation: 1498
I am building my first app with react native. I am, for now, storing locally with AsyncStorage the user data. This app is going to make users interact with each other, I am looking at realm.io but for my understanding all the mobile apps save the data locally then sync it to a database. I am not sure if this is the way and I am doing correct. Basically what I want to do is :
Is this the correct way? For example if is a chat and I want to store the data for both users in to the database, how do I do? So to recap, how do I store the app data for all users in a live database that is on a server?
Upvotes: 0
Views: 1652
Reputation: 146
What you're looking for is redux-persist https://github.com/rt2zz/redux-persist
What redux persist does is handle all the local storage things on its own any time it changes. So when you reopen the app everything that you want is there. You handle the database loading as you would normally and send it to your redux store and replace the old data.
Persist also has a black and white list for some of the things that you may or may not want to be saved. If you want to save everything in the store though it does it by default.
If you have important things that you want to be saved, you'll want to move it into the store if you have it in the state, because it does not save state.
Upvotes: 2