反应原生firebase用户注册问题

时间:2018-01-09 09:54:13

标签: firebase react-native firebase-authentication undefined

我是反应原生的新手,目前正在使用firebase对react-native进行用户身份验证。

截至目前,我正在进行用户注册功能,用户注册并将凭据保存到firebase

但是我收到了

的错误
  

undefined不是一个函数(评估'this.setState({error:   “,loading:true})')

我不知道出了什么问题以及如何修复它并需要一些帮助谢谢!

我的用户注册页面的代码是

class RegisterScreen extends React.Component{

    _onPressSubmit(){
        console.log('register submit btn pressed')

        this.state({ error: '', loading: true});

        const { email, password } = this.state;

        firebase.auth().createUserWithEmailAndPassword(email, password)
        .then(() => { 
            this.state({error: '', loading: false});
            this.props.navigation.navigate('Main');
        })
        .catch(() => {
            this.state({error: 'Registration failed', loading: false});
        })
    }

    render() {      
        return (
            <ScrollView> 
                <View style = {[styles.container]}> 

                    <Text></Text>

                    <TextInput  style = {[styles.textSpace]}
                        //label = 'Email Address' 
                        placeholder = 'Email' 
                        keyboardType = 'email-address'
                        //TBA />

                    <TextInput 
                       // label = 'Password'
                        placeholder = 'Password'
                        //TBA />

                    <Text style={styles.textPadding}></Text> 

                    <Text style={styles.textPadding}></Text>

                    <Button 
                        onPress = {this._onPressSubmit}
                        title = 'Submit' />
                </View>
            </ScrollView>
        );
    }    
}

2 个答案:

答案 0 :(得分:0)

而不是this.state()使用this.setState({}) 变异时

答案 1 :(得分:0)

错误表明状态不是Component的功能。

也许你想设置状态?如果是这样,而不是:

this.state({ error: '', loading: true});

它应该是:

this.setState({ error: '', loading: true});

theres在代码示例中至少出现3次。