[英]How do I put my firestore data into a table?
export function ListData() {
const [dataList,setDataList] = useState([]);
useEffect(() =>{
async function callData(){
const result = await GetAllDataOnce()
return result
}
setDataList(callData())
},[])
async function GetAllDataOnce() {
const querySnapshot = await getDocs(collection(db, "repos"));
var data = [];
querySnapshot.forEach(doc => {
data.push({
id: doc.id,
data: doc.data()
})
})
return data;
}
return (
<table>
{dataList.map(returndata => (
<tr key={returndata.id}>
<td>{returndata.data}</td>
</tr>
))}
</table>
)}
Here is the data I am working with:这是我正在使用的数据: This is using react with firebase firestore.这是使用与 firebase firestore 的反应。 I want to display each name with their respective desc, icon, and repo.我想显示每个名称及其各自的描述、图标和回购协议。 I am getting error我收到错误
table.js:37 Uncaught TypeError: dataList.map is not a function table.js:37 Uncaught TypeError: dataList.map 不是 function
I think you could try to debug by printing value from the function callData, then check if it is an array.我想你可以尝试通过打印 function callData 的值来调试,然后检查它是否是一个数组。
async function callData(){
const result = await GetAllDataOnce()
console.log(result)
console.log(typeof result)
return result
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.