Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For @realm/react export createUseQuery & createUseObject #6252

Closed
bimusiek opened this issue Nov 15, 2023 · 10 comments
Closed

For @realm/react export createUseQuery & createUseObject #6252

bimusiek opened this issue Nov 15, 2023 · 10 comments

Comments

@bimusiek
Copy link
Contributor

bimusiek commented Nov 15, 2023

Problem

We want to slowly migrate our codebase to @realm/react. Currently, we have deeply integration of Realm into our React app using our own code.

We would love to gradually migrate, thus we need ability to pass our own useRealm, but both createUseQuery, createUseObject are not exported.

Solution

Simply export both createUseQuery, createUseObject

Alternatives

Currently we do pnpm patching to export both those functions.

How important is this improvement for you?

I would like to have it but have a workaround

Feature would mainly be used with

Atlas Device Sync

@bimusiek
Copy link
Contributor Author

Additional advantage for us is ability to have 2 Realms. Basically we have one Realm.Sync and another Realm.Local that is used as a replacement for memory heavy workloads. But we don't want to sync that one.

With these functions, we could have 2 realm instances with react functionality.

@takameyer
Copy link
Contributor

@bimusiek we expose a creatRealmContext method, which allows you to expose multiple realms.
This takes a Realm configuration as an argument and returns an object containing the RealmProvider and hooks associated with the Realm you are configuring.
Is this sufficient for your use-case?

@bimusiek
Copy link
Contributor Author

Ah, right. Yes, that would probably be enough. Unfortunately due to the way we bundle our app for Electron & React Native, we still cannot use the included library as it imports Realm directly. And we need to do some workaround with require() for Electron so it imports it from Node environment rather than Webpack bundle. (because then it tries to bundle RN inside)

Closing the comment for now.

@kraenhansen
Copy link
Member

we need to do some workaround with require() for Electron so it imports it from Node environment rather than Webpack bundle. (because then it tries to bundle RN inside)

@bimusiek I'd be interested to know if you've created an issue for this and if this issue is also experienced with realm@12.

@bimusiek
Copy link
Contributor Author

@kraenhansen No issue as it is old workaround from even before Realm was acquired by Mongo. We have the task on our upcoming work to update from Realm@11 to @12. I will check if workaround is not needed, if that won’t be a case I will create the issue.

@kraenhansen
Copy link
Member

kraenhansen commented Nov 20, 2023

update from realm@11 to @12

That should be seamless, please let os know if it's not! 😊

@takameyer
Copy link
Contributor

@bimusiek I did recently create an electron example to ease integration with realm. Maybe it's helpful?
https://github.com/realm/realm-js/tree/main/examples/electron-todo-list

@bimusiek
Copy link
Contributor Author

@takameyer @kraenhansen I am into the process of upgrade and besides some typing issues it went quite smooth. I got rid of our custom require() workaround.

But I am getting error in Electron on renderer side:
Error: Cannot find module 'realm'

And in devserver:
Package path . is not exported from package

And I have no clue why this could be happening.

@bimusiek
Copy link
Contributor Author

And the React Native packager throws:

error: Error: Unable to resolve module realm/realm-constants.json from /Users/bimusiek/Developer/FreeYourMusic/app/node_modules/.pnpm/[email protected][email protected]/node_modules/realm/dist/bundle.react-native.js: 

@bimusiek
Copy link
Contributor Author

Ok, I was missing craco and the webpack external configuration for Electron.
There is still one small issue: #6270 but I was able to patch it on my side by creating the missing file manually.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants