MongoDB Developer
Realm
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
Realmchevron-right

Using Expo and Realm React Native with expo-dev-client

Diego FrenichePublished Mar 04, 2022 • Updated Aug 26, 2022
React NativeRealmJavaScriptTypeScript
Copy Link
facebook icontwitter iconlinkedin icon
random alt
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
In our last post on how to build an offline-first React Native mobile app with Expo and Realm React Native, we talked about a limitation of using Realm React Native and Expo where we stated that Realm React Native is not compatible with Expo-managed workflows. Well, wait no more, because now Expo works with Realm React Native and we have a nice custom development client that will have roughly the same functionality as Expo Go.

Creating a React Native app using Expo and Realm React Native in one simple step

Yes, it sounds like clickbait, but it's true. If you want to build a full application that uses TypeScript, just type in your terminal:
If you'd rather do JavaScript, just type:
After either of these two, change to the directory containing the project that has just been created and start the iOS or Android app:
Or
This will create a prebuilt Expo app. That is, you'll see ios and android folders in your project and this won't be a managed Expo app, where all the native details are hidden and Expo takes care of everything. Having said that, you don't need to go into the ios or android folders unless you need to add some native code in Swift or Kotlin.
Once launched, the app will ask to open in ReactRealmJSTemplateApp, not in Expo Go. This means we're running this nice, custom, dev client that will bring us most of the Expo Go experience while also working with Realm React Native.
We can install our app and use it using yarn ios/android. If we want to start the dev-client to develop, we can also use yarn start.

Adding our own code

This template is a quick way to start with Realm React Native, so it includes all code you'll need to write your own Realm React Native application:
  • It adds the versions of Expo (^44.0.6), React Native (0.64.3), and Realm (^10.13.0) that work together.
  • It also adds expo-dev-client and @realm/react packages, to make the custom development client part work.
  • Finally, in app, you'll find sample code to create your own model object, initialize a connection with Atlas Device Sync, save and fetch data, etc.
But I want to reuse the Read it Later - Maybe app I wrote for the last post on Expo and Realm React Native. Well, I just need to delete all JavaScript files inside app, copy over all my code from that App, and that's all. Now my old app's code will work with this custom dev client!

Putting our new custom development client to work

Showing the debug menu is explained in the React Native debug documentation, but you just need to:
Use the ⌘D keyboard shortcut when your app is running in the iOS Simulator, or ⌘M when running in an Android emulator on macOS, and Ctrl+M on Windows and Linux.
Android Debug MenuiOS Debug Menu
Read it Later app running, with the debug menu showing upRead it Later app running, with the debug menu showing up
As this is an Expo app, we can also show the Expo menu by just pressing m from terminal while our app is running.
Terminal showing debug menu. At the back, there's an iOS simulator, showing the Expo debug menu after pressing m.

Now do Hermes and react-native-reanimated

The Realm React Native SDK has a hermes branch that is indeed compatible with Hermes. So, it'll work with react-native-reanimated v2 but not with Expo, due to the React Native version the Expo SDK is pinned to.
So, right now, you have to choose:
  • Have Expo + Realm working out of the box.
  • Or start your app using Realm React Native+ Hermes (not using Expo).
Both the Expo team and the Realm JavaScript SDK teams are working hard to make everything work together, and we'll update you with a new post in the future on using React Native Reanimated + Expo + Hermes + Realm (when all required dependencies are in place).

Recap

In this post, we've shown how simple it is now to create a React Native application that uses Expo + Realm React Native. This still won't work with Hermes, but watch this space as Realm is already compatible with it!

One more thing

Our community has also started to leverage our new capabilities here. Watch this video from Aaron Saunders explaining how to use Realm React Native + Expo building a React Native app.
And, as always, you can hang out in our Community Forums and ask questions (and get answers) about your React Native development with Expo, Realm React Native and MongoDB.

Copy Link
facebook icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial

Migrating Your iOS App's Realm Schema in Production


Sep 01, 2022
Code Example

Find our Devices - A locator app built using Realm


Jun 15, 2022
Tutorial

Most Useful iOS 15 SwiftUI Features


Sep 01, 2022
Tutorial

Realm Data and Partitioning Strategy Behind the WildAid O-FISH Mobile Apps


Sep 23, 2022
Table of Contents