Home > OS >  How to handle states with redux and realm [react-natve]
How to handle states with redux and realm [react-natve]

Time:01-29

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.

  1. Redux is state management library and Realm is just database solution. I guess you are trying to say redux persist/asyncstorage. redux persist allows you to store key-pair value in your app while realm is way more efficient when storing large amount of data.

  2. Yes, it is right to use redux and realm together. Redux is used as state management, managing all the UI state, while Realm is served as database to store your data.

Example (Messaging App)

  1. When load messages from API, store it in realm directly.
  2. Add a listener for realm, listen the data changes and expose them in redux state.
  3. You may whitelist/blacklist your state in redux persist by destroy these state when you killed the application.

Here is my small explanation.

  •  Tags:  
  • Related