Help to understand how sync is really supposed to work in react-native


I’m a newbie to both react-native and realm, but not with programming, so I’m sure I’m doing something wrong.

The scenario is I have an offline-first react native app using realm.

When I run a completely local realm file, everything works fine. I can load data (from the phone contacts) and interact with it fine.

realm: new Realm({schema: schemas, schemaVersion: 3,})
Then I tried to sync it with a Realm Object Server like this:

    Realm.Sync.User.login(app_config.auth_uri, app_config.default_login, app_config.default_password).then(user => {
    console.log("logged into Realm Object Server")
    const config = {
        sync: {
            user: user,
            url: app_config.db_uri,
            error: err => console.log(err)
        schema: schemas,
        schemaVersion: 3,

    this.realm = new Realm(config);

}).catch(error => {
    console.log('Error with sync setup to ' + app_config.auth_uri + ' with : ' + error)

and it connects but there is no syncing. Worse still, because it is now in an async context, everything that expected ‘realm’ to be set is failing - lots of ‘null’ exceptions.

So my question:

How should this be working. My expectation is I get a realm immediately from both calls and the syncing part should be happening in the background. If it fails i.e. couldn’t connect or loses connection, the app should still be working.

Am I wrong, does anyone have a fuller working example of this?

Will continue search but I really appreciate your help!


Did you ever get this figured out?

I think I’m experiencing the same issue you’re describing regarding the lack of syncing when opening the Realm synchronously. If I open the Realm asynchronously, synchronization happens as expected, but this is not the user experience I want to deliver.


The OP’s issue is there is either a local realm or a synced realm. If you create a local realm and then want to convert it to a synced realm you’ll need to copy it. This stackoverflow issue is pretty much the same issue with a solution provided by one of Realm’s staff: