Realm (Mobile)
MongoDB Developer Center
chevron-right
Developer Topics
chevron-right
Products
chevron-right
Realm (Mobile)
chevron-right

Using Expo and Realm with expo-dev-client

Diego FrenichePublished Mar 04, 2022 • Updated May 13, 2022
Realm (Mobile)
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
, we talked
about a limitation of using Realm and Expo
where we stated that Realm is not compatible with Expo-managed workflows. Well, wait no more, because now Expo works with Realm 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 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.
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, so it includes all code you'll need to write your own Realm 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 Realm 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
. 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 + 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. 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 MongoDB Realm + 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 and MongoDB.

Copy Link
facebook icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Tutorial
OAuth & MongoDB Realm Serverless Functions

Jan 27, 2022
Code Example
Build Offline-First Mobile Apps by Caching API Results in Realm

Sep 13, 2021
Tutorial
Persistence in Unity Using Realm

Oct 14, 2021
Tutorial
How to Write End-to-End Tests for MongoDB Realm Serverless Apps

Jan 14, 2022
Table of Contents