每次我删除/重新启动我的模拟时,我都会收到上述错误消息。有没有办法插入一个虚拟用户对象,使我能够通过“常量”进行解析并获得实际登录?
import React from 'react';
import { StyleSheet, AppRegistry, TextInput, Text, View, Alert, } from 'react-native';
import Realm from 'realm';
logBookSchema = {schema: [{
name: 'LogBook',
properties: {
logNum: 'int',
},
}]
}
class LogBook extends Realm.Object {}
const realm = new Realm({sync: {user: Realm.Sync.User.current, url: 'realm://localhost:9080/~/logbook',error: err => alert(err)},logBookSchema});
export default class App extends React.Component {
render() {
Realm.Sync.User.login('http://localhost:9080', 'test@user2.com', 'test').then (user => {
Realm.open({logBookSchema, sync: {user: user, url: 'realm://localhost:9080/~/logbook',error: err => alert(err)}});
});
return (
<View><Text></Text><Text>Logged in</Text></View>
)
}
}
最佳答案
终于离开了厄运之谷。这是我的方法:
export default class LoginScreen extends React.Component {
constructor(props) {
super(props);
this.state = { realm: null };
}
componentWillMount() {
Realm.Sync.User.login('http://192.168.2.105:9080', 'test@user2.com', 'test')
.then (user => {
Realm.open({schema: [LogBook],
sync: {user: user, url: 'realm://192.168.2.105:9080/~/logbook',error: err => alert(err)}
})
.then(realm => {
this.setState({ realm });
});
});
}
render() {
if (!this.state.realm) {return (
<View><Text></Text><Text>Loading</Text></View>
)}
else {
return (
<MyApp />
);
}
}
}
关于react-native - Realm :用户必须是 'object' 类型,得到(未定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48041699/