Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How can export a default realm configuration function without getting an error Realm

$
0
0

I'm trying to export useRealm which will enable me to use in other files, e.g redux-thunk.The code i wrote:

import Realm from "realm";import { getRealmApp } from "../functions/realmConfig";import { ItemSchema } from "./itemSchema";const app = getRealmApp();const user = Realm.User;const useConfig = {  schema: [ItemSchema], //other schema will be added in the future  sync: {    user: user.prototype,    partitionValue: user.name,  },};export const useRealm = Realm.open({  schema: [ItemSchema],  sync: {    user: user.prototype,    partitionValue: app.currentUser?.id!,    error: (e) => {      console.log(e);    },  },});

But this configuration tends to throw an error:

Uncaught Error: Invalid object. No _instance member    at Function.open (/Users/newuser/workspace/programming/desktop/numberz/node_modules/realm/lib/extensions.js:183)    at eval (index.ts?77fd:17)    at Object../src/realm/index.ts (renderer.js:5394)    at __webpack_require__ (renderer.js:791)    at fn (renderer.js:102)    at eval (index.ts?788b:3)    at Object../src/redux/testReducer/index.ts (renderer.js:5427)    at __webpack_require__ (renderer.js:791)    at fn (renderer.js:102)    at eval (index.ts?76a6:9)

I've tried example but they were using react context, which i can not use as i'm building a big app thats way to complex for context api


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>