【发布时间】:2018-11-16 04:49:32
【问题描述】:
我想根据从文本输入中输入的用户信息更新 firebase - 数据库中的值。 我像往常一样在文本输入的 onChange 事件中设置状态。但是当我最终想用输入的信息更新数据库时,什么也没有发生。我用硬编码的字符串而不是状态值进行了测试,这是有效的,它更新了数据库。 我怎样才能使它适用于状态值?
constructor(props) {
super(props);
this.state = {
name: "",
surName: "",
email: ""
};
}
<View style={styles.surNameHolder}>
<Text style={styles.surNameLabel}>Nachname</Text>
<TextInput
style={styles.surNameText}
placeholder="Musterman"
keyboardType="default"
hideUnderline={true}
onChange={surName =>
this.setState({ surName: surName })
}
/>
</View>
<View style={styles.nameHolder}>
<Text style={styles.nameLabel}>Vorname</Text>
<TextInput
style={styles.nameText}
placeholder="Max"
keyboardType="default"
hideUnderline={true}
onChange={name => this.setState({ name: name })}
/>
</View>
</View>
<View style={styles.mailHolder}>
<Text style={styles.mailLabel}>E-Mail</Text>
<TextInput
style={styles.mailText}
placeholder="musterman@max.com"
keyboardType="default"
hideUnderline={true}
onChange={value => this.setState({ email: value })}
/>
</View>
<View
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 20
}}
>
<View center style={styles.postButton}>
<TouchableOpacity onPress={this.updateUserData}>
<Text style={styles.postButtonText}>
AGB´s akzeptiert
</Text>
</TouchableOpacity>
</View>
updateUserData = () => {
if (this.state.name) {
if (this.state.surName) {
if (this.state.email) {
var currentUserRef = firebase
.database()
.ref("Users")
.child(firebase.auth().currentUser.uid);
currentUserRef.update({
firstName: this.state.name
});
}
}
}
};
【问题讨论】:
标签: javascript firebase react-native firebase-realtime-database react-native-firebase