Maintaining sync realm between app screens


#1

Hi,

After user login - what is the best practice to access a synced realm in all my app screens (I use react-navigation)?

sync realm requires a user object in the configuration object.I tried using Realm.Sync.User.current but this raise an error when I initially launch the app as the user object is still empty (I created a separate file for the sync realm initialization which I import to all other pages/screens).

what is the best practice to do it ?

Thank you

Yuval


#2

@yuvalkro Typically you pass the realm reference to the next view controller, see here for an example tutorial:
https://docs.realm.io/cloud/ios-todo-app


#3

Thank you Ian, helpful as always.
Understood your point.Trying to figure out the best practice to do it in react-native.


#4

I have found that React context also works great for this in case anyone runs across this thread.