29

I am about to undertake the development of a React Native app and am thoroughly convinced of the benefits of managing the app's state using Redux, however I'd like to make the app's data available whilst offline by using Realm for persistent storage. What I'm wondering is how Redux will play with Realm?

The app I'm developing will pull a large amount of JSON data via a RESTful API and then I'd like to persist this data to local storage - Realm seems to be an excellent option for this. What I'm unsure of however is how the Realm database will exist within the Redux store? Will it have to exist external to the store? Is using Realm within a Redux based app somehow a contradiction?

I've had a good search for articles describing the use of Realm, or other storage options (Asyncstorage or SQLite) for large datasets with Redux and could find little information.

4
  • 3
    Why not define LOAD/SAVE actions that actually make async calls to the realm database to load/save the right pieces of data. Sort of like treating th realm database like another service, because you can't load very large amounts of data in one shot. Commented Oct 21, 2016 at 5:39
  • Might I ask, how large is "large"? Commented Feb 8, 2017 at 0:53
  • hey, i'm having a similar issue: i extract and display data from Firebase realtime database into react native application for both iOS and android. My database is large (it contains more 14400 line) and it's mandatory for me to have all this data displayed even if there is no internet connection. So, i was thinking of making a jSON file that i read and write on data whenever there is no connection, but , then i found Realm. So do you think it meets with my needs ? i'm also using Redux in my app, will it have contradiction in my app ? Thank you Commented May 2, 2017 at 14:55
  • This redux-persist issue discusses this particular subject. I don't think it will happen Commented May 19, 2017 at 9:29

1 Answer 1

13

The redux store is good when you have only react components dealing with the data. The store is a good way to maintain your application's state. For example, you do not need Realm to store the current login status or flags indicating whether the user has skipped login. The redux store wins the game here.

On the other hand, Realm is the best when you have to deal with complex queries or a large amount of data to be stored. The advantage of having Realm is that the data can be accessed within your react components as well as non-react components/classes easily. Realm gives you the advantage to monitor your data with the Realm Browser and build relationships between your models. Realm also wins the race if you have to do any offline sync.

Will it have to exist external to the store - Yes.

Is using Realm within a Redux based app somehow a contradiction - It depends upon what you are using the storage for.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for your excellent response :-) Since writing this question I have a much better understanding on what redux is and how it is used and I totally agree with your statements above. I am still not completely sure whether I need to use Realm or whether a Redux store is going to be adequate. I suspect the later for my use case. Thanks again.
We are making a similar decision - did you make a final decision, and if so, are you happy with the choice? We have implemented Realm somewhat already - but are finding it to add a lot of overhead to our project and are considering removing it. I just wonder how much offline matters for many mobile apps - especially as ours is ecom and not something people ever expect to do offline.
I am the Co-Founder of clockit.io. Here at clockit we store users geo location in the background as a part of offline location tracking. Redux vs Realm totally depends upon your application's requirement. If you are using ecom, using realm will cause an overhead unless you have very specific offline storage requirements.
In my humble opinion, Redux and Realm shoudn't be exclusive to each other. It's only a matter of sorting out different layers of one's application. React and Redux is mainly on the presentation layer where a Redux store(even though it's named a store) is not and should not be a persistence device of any sort. Redux store simply stores different variables for UI components to behave accordingly. On the other hand, Realm solves problems at persistence layer. One should fetch data and display them using React and Redux, and cache them offline using Realm according to one's business logic.
does Realm itself offer some of the benefits of Redux then? that is, does it offer it's own way to automatically update UI components if the data changes?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.