Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Realm in React Native app with Redux

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.

like image 444
oldo.nicho Avatar asked Oct 21 '16 01:10

oldo.nicho


People also ask

Can react native be used with Redux?

Redux is a standalone state management library, which can be used with any library or framework whether it's React, React Native or any other view library.

Why We Use realm in react native?

The Realm React Native SDK allows you to use Realm Database and backend Apps from React Native applications for iOS and Android written in JavaScript or TypeScript. The React Native SDK does not support JavaScript or TypeScript applications written for web browsers. For that use case, you should consider the Web SDK.

Can I use realm with Expo?

The Realm Expo template provides a fully working React Native application that you can use to bootstrap your app development project with Realm.

How do I use React Redux in React Native?

Redux in a React Native App. As we mentioned earlier, Redux is a state management tool, and you will use it to manage all the states of the application. Our application is a subject selector where the user chooses the subjects from a predefined list. First, install the Redux packages. npm install redux react-redux

How do I run a react native app on Android emulator?

To build the app for iOS, execute the command npx react-native run-ios. To run it on an Android emulator, execute npx react-native run-android.

Can I really use React Native to build production-ready mobile apps?

And yes: you can really use React Native to build production-ready mobile applications! Some example: Facebook, Palantir, and TaskRabbit are already using it in production for user-facing applications. What is Redux?

What is React-Redux yarn add Redux?

yarn add react-redux yarn add redux React Redux is the official React binding for Redux. It lets your React components read data from a Redux store, and dispatch actions to the store to update data. As of React Native 0.18, React Redux 5.x should work with React Native.


1 Answers

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.

like image 156
Jaseem Abbas Avatar answered Oct 20 '22 01:10

Jaseem Abbas