Javascript 如何使用react native在firebase中显示日期
各位!! 我已将我的应用程序与firebase连接,但我无法在我的应用程序上显示用户数据: 请你把我的密码通读一遍好吗Javascript 如何使用react native在firebase中显示日期,javascript,reactjs,firebase,react-native,firebase-realtime-database,Javascript,Reactjs,Firebase,React Native,Firebase Realtime Database,各位!! 我已将我的应用程序与firebase连接,但我无法在我的应用程序上显示用户数据: 请你把我的密码通读一遍好吗 componentDidMount() { firebase.auth().onAuthStateChanged(user => { if(user!=null){ userId = firebase.auth().currentUser.uid }else { this.props.navigation.navigate("Loading");
componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
if(user!=null){
userId = firebase.auth().currentUser.uid
}else {
this.props.navigation.navigate("Loading");
}
}),
firebase.database().ref('Users/').on('value', function (snapshot) {
console.log(snapshot.val()); //this work
// let name = snapshot.val().name;
// this.setState ({users :name,}) //this not work
});
}
。。。。。。及
<View style={styles.contain}>
<ProfileDetail
// image={userData.image}
// textFirst={users.name}
// point={userData.point}
textSecond={this.state.name} //. i'd like to display the child on this
textThird={currentUser.email}
// onPress={() => navigation.navigate("ProfileExample")}
/>
更改此项:
firebase.database().ref('Users/').on('value', function (snapshot) {
console.log(snapshot.val()); //this work
// let name = snapshot.val().name;
// this.setState ({users :name,}) //this not work
});
为此:
firebase.database().ref('Users/').on('value', ((snapshot) => {
console.log(snapshot.val()); //this work
let name = snapshot.val().name;
this.setState ({users :name,})
});
使用而不是声明普通函数
箭头函数对此没有自己的定义。使用封闭词法范围的此值;箭头函数遵循普通变量查找规则。因此,当搜索当前范围中不存在的this时,arrow函数最终从其封闭范围中找到this
非常感谢。它不会出错,但我正在使用这个'textssecond={this.state.name}'它不显示什么@明蒂ếnPhạmsomething仍然错误,它不起作用,我称它为.state.users,但你敢把它添加到state中对不起,我的回答太晚了,但它起作用了。谢谢