2017-12-31 54 views
0

시뮬레이션을 지우거나 다시 시작할 때마다 위의 오류 메시지가 나타납니다. 'const'를 통해 구문 분석하고 실제 로그인을 얻을 수있는 더미 사용자 객체를 삽입하는 방법이 있습니까?영역 : 사용자가 'object'유형이어야합니다. (정의되지 않음)

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', '[email protected]', '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> 
) 
    } 
} 

답변

1

마지막으로 운명의 계곡을 떠났다. 여기에 내 접근 방식 :

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', '[email protected]', '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 /> 
    ); 
    } 
    } 
}