2017-12-31 58 views
0

シミュレーションを消去/再起動するたびに上記のエラーメッセージが表示されます。私が 'const'を解析して実際のログインに入ることを可能にするダミーのユーザーオブジェクトを挿入する方法はありますか?レルム:ユーザーは 'オブジェクト'タイプである必要があります(未定義)

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 /> 
    ); 
    } 
    } 
} 
関連する問題