需要在列表中显示用户的个人资料图片并从Firestore检索数据。 考虑下面的代码。
user: {},
};
unsubscribe = null;
componentDidMount() {
const user = this.props.uid || Fire.shared.uid;
this.unsubscribe = Fire.shared.firestore
.collection("users")
.doc(user)
.onSnapshot(doc => {
this.setState({user: doc.data()});
});
}
//one of the methods in may firestore class.
get uid() {
return (firebase.auth().currentUser || {}).uid;
}