[英]retrieving data from firestore using uid react
我對反應非常不熟悉,但是下面有這段代碼,我需要根據登錄的人從數據庫中調用數據。我在該頁面上記錄了 uid,但不知道如何使用 firebase具體的uid。
import React from 'react';
import firebase from 'firebase';
const firestore = firebase.firestore();
class ProfilePage extends React.Component {
state = {
profiledata : null
}
componentDidMount(){
firestore.collection('profiledata')
.get()
.then((snapshot) => {
const profiledata = []
snapshot.forEach(function(doc){
const data = doc.data();
profiledata.push(data);
}
)
this.setState({profiledata : profiledata})
})
}
render(){
return(
<div className='profile'>
<h1>User</h1>
{
this.state.profiledata &&
this.state.profiledata.map( profiledata => {
return(
<div>
<p>
First Name : {String(profiledata.firstname)}
Last Name : {String(profiledata.lastname)}
Company Name : {String(profiledata.companyname)}
</p>
</div>
)
})
}
</div>
)
}
}
export default ProfilePage;
現在這整個事情正在返回所有在 firebase 中注冊的用戶。 如何更改它以根據 uid 專門調用用戶詳細信息?
在.get()之前添加.doc(uid):
firestore.collection('profiledata')
.doc(uid)
.get()
.then(doc => {
console.log(doc.data());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.