React Native:await是一个保留字

Ama*_*oux 1 react-native asyncstorage

我试图保存我的用户登录然后在他的管理页面上重定向他的事实但是当我使用await时我得到了这个错误:

await是一个保留字(101)

另一件事,一旦我的用户注册,我想将他发送到一个新的页面,而不是一个"幻灯片页面",我们可以用右上角的箭头返回.我怎样才能做到这一点?

这是我的代码:

 login(){
    firebase.auth().signInWithEmailAndPassword(this.state.emailLogin, 
    this.state.passwordLogin).then((user) =>  {
        // Send the user to the next step
        try {
            await AsyncStorage.setItem('@MySuperStore:key', 'I like 
            to save it.');
        } catch (error) {
            // Error saving data
        }
        const { navigate } = this.props.navigation; 
        navigate('Admin');
    }).catch(function(error) {
        var errorCode = error.code;
        var errorMessage = error.message;

        if (errorCode === 'auth/wrong-password') {
            alert('Wrong password.');
        } else {
            alert(errorMessage);         
        }
        console.log(error);
    });
}
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

Bru*_*der 8

await在函数中使用时,必须将其标记为async

 this.state.passwordLogin).then( aysnc (user) =>  {
 ...
 })
Run Code Online (Sandbox Code Playgroud)