Open aight8 opened 7 months ago
@aight8 Thank you raising the issue. We don't have a quick fix but we use React Native Navigation on one of our examples. I will bring it up with the team to get some ideas.
Hi thank you. I made it work by a fork and export createUseObject
, createUseQuery
, createUseRealm
from '@realm/react' etc. (don't know if the list is complete).
Just for clearification of the problem (that we understand each other correctly), the examples uses react-navigation (single React DOM based), I use react-native-navigation (many React DOM based)
In the example it's like:
- AppProvider (App.tsx)
- UserProvider (otherwise show Login component)
- RealmProvider (AuthenticatedApp.tsx)
- ... the whole app incl. navigation...
A react-native-navigation
based app is it like:
// HomeScreen
- AppProvider
- UserProvider
- RealmProvider
// SettingsScreen
- AppProvider
- UserProvider
- RealmProvider
// Tab1ContentScreen
- AppProvider
- UserProvider
- RealmProvider
// Overlay1Screen
- AppProvider
- UserProvider
- RealmProvider
// Modal1Screen
- AppProvider
- UserProvider
- RealmProvider
// TopBarHeaderScreen
- AppProvider
- UserProvider
- RealmProvider
// etc.
So think about, every Root View, Overlay/Modals are total separately rendered React DOM's. Some of the screens are rendered and visible at the same time. (e.g. simultaneously: Tab1ContentScreen, Top1ContentTopBarScreen, Modal1Screen)
This has the following consequences:
Motivation
react-native-navigation
offer a particularly native feeling for the user. it would be nice if these applications could use realm.The easiest way to solve this issue, to let the user provide Realm and Realm.App object.
Would love to see a solution for this.
@aight8 and @nicolaosm - wanted to mention that we're also tracking this issue for a similar feature that you might want to 👍 and watch: https://github.com/realm/realm-js/issues/6283
@aight8 @nicolaosm
Realm React v0.8.0 now supports using an existing Realm instance with a RealmProvider
or createRealmContext
!
Should provide a nice solution to this usecase.
Problem
I use react-native-navigation, which uses many React DOM's (every Screen is a separate DOM) Every screen shares a common Wrapper, which initializes Realm, App and optionally the User Context. The problem is that: 1) AppProvider and RealmProvider creates and configure a fresh instance of Realm.App and Realm object for the DOM. I just want to initialize and reuse the global realm and realm.app object externally. Also the observing doesn't work like this, I don't know exactly why, but I think that the global realm and realm.app object only corresponds to the last changed screen. 2) I have tried to simply set Realm and Realm.App through the Context.Provider but they are not exported. Also, the AppProvider contains some extra logic (also renders AuthOperationProvider).
Solution
As result the Realm and Realm.App Object is managed externally and as side effect the code React DOM stays little bit cleaner.
Alternatives
There is no real alternatives. I currently forked realm-js, exported the React Context.Provider, manually add AuthOperationProvider etc.
How important is this improvement for you?
Dealbreaker
Feature would mainly be used with
Atlas Device Sync