I'm working on a complex application using react-native, and I'm struggling on how to manage states and persist-states. I'd like to achieve something like instagram, loading posts one time in redux and then save a bit of them in local-memory, to show something when the user open the app without internet connection.
Now to handle states across the app I'm using react-redux even if it cause some lag on react-navigation transition, and to save data locally suggest me to use redux-persist for low-complexity apps and realm for medium/hight-complexity apps.
What's exactly the practical difference between redux and realm? (excluding the fact that the former doesn't persist when app is closed).
Is it right to use both redux and realm? If so what's the best implementation?
Thank you. Please no useless question, I've been clear.
CodePudding user response:
I am also working on messaging app (consider complex app?) and here is my answer to your question.
Redux is
state managementlibrary and Realm is justdatabasesolution. I guess you are trying to say redux persist/asyncstorage.redux persistallows you to store key-pair value in your app whilerealmis way more efficient when storing large amount of data.Yes, it is right to use redux and realm together. Redux is used as
statemanagement, managing all the UI state, while Realm is served as database to store your data.
Example (Messaging App)
- When load messages from API, store it in
realmdirectly. - Add a listener for
realm, listen the data changes and expose them inreduxstate. - You may whitelist/blacklist your state in
redux persistby destroy these state when you killed the application.
Here is my small explanation.
