28
votes

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.

1
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. - iamnat
Might I ask, how large is "large"? - JeremyKun
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 - user3521011
This redux-persist issue discusses this particular subject. I don't think it will happen - DerpyNerd

1 Answers

12
votes

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.