【发布时间】:2021-02-08 17:26:08
【问题描述】:
当我想导出默认领域配置 useRealm 以便能够在其他文件中使用它时遇到错误
import Realm from "realm";
import { getRealmApp } from "../functions/realmConfig";
import { ItemSchema } from "./itemSchema";
export const app = getRealmApp();
export const useRealmApp = getRealmApp();
export const user = useRealmApp.currentUser;
export const partitionValue = useRealmApp.currentUser.id;
export const config = {
schema: [ItemSchema], //other schema will be added in the future
sync: {
user: user,
partitionValue: partitionValue, //app.currentUser.id,
},
};
export const useRealm = new Realm(config);
预期的结果是,如果用户没有登录,它应该会显示一个登录屏幕。但是它会抛出这个错误并且不给我登录的机会:
index.ts?77fd:9 Uncaught TypeError: Cannot read property 'id' of null
at eval (index.ts?77fd:9)
at Object../src/realm/index.ts (renderer.js:5394)
at __webpack_require__ (renderer.js:791)
at fn (renderer.js:102)
at eval (testIndex.tsx?956d:10)
at Object../testIndex.tsx (renderer.js:5438)
at __webpack_require__ (renderer.js:791)
at fn (renderer.js:102)
at eval (App.tsx?d35d:4)
【问题讨论】:
标签: javascript mongodb typescript react-native realm