How to do client reset with @realm/react?


Thank you for this amazing service. When opening a Realm, one could handle client resets with the following code:

const handleRealmSyncError: Realm.ErrorCallback = useCallback(
    (_session, error) => {
      if (realmRef.current) {
        if ( === 'ClientReset') {
          Realm.App.Sync.initiateClientReset(realmApp, realmPath);
          realmRef.current = null;

and opening a Realm with the following sync config:

sync: {
  user: currentRealmUser,
  error: handleRealmSyncError,

But with @realm/react, we cannot use the useRealm hook in the same component where RealmProvider is declared, and thus I have no idea where how to handle any sync errors. We are paying customers and have a couple of deadlines to rush. Please advise, thank you very much!

The reason why we need these lines:

const realm = useRealm()

is because we need to close the realm before performing a client reset. Any MongoDB employees can help us out or is there any other info we can provide to help find a solution for this?

@Chee_Kit_C excuse the late reply, the forums can be a bit noisy. This is indeed a use case we hadn’t considered and should be implemented. I believe I could provide a ref prop to the RealmProvider and set the value when it’s rendered. That should make what you are trying to do possible.
Could you please open an issue on our github repository? This way we can get this planned and track progress.


@Andrew_Meyer thank you for the quick response! I’ve opened up a new issue: Expose realm ref when using RealmProvider in @realm/react · Issue #4571 · realm/realm-js (