简体   繁体   English

如何将我的 Firestore 数据放入表中?

[英]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.

相关问题 如何将我的数据从 firestore 转换为身份验证用户 - How do I convert my data from firestore into authentication users 如何将数据从我的数据库 (Firebase Firestore) 发送到我的 React Native 应用程序? - How do I send data from my database (Firebase Firestore) to my React Native app? 如何使用 StreamBuilder 显示我的 Cloud firestore 数据库中一个特定文档的数据? - How do I use StreamBuilder to display the data from ONE specific document in my Cloud firestore database? 如何从 Firebase Firestore 集合中指定文档的特定字段获取数据并将其显示到我的 UI? - How do I get data from a specific field of the specified document inside a Firebase Firestore collection and display it to my UI? 如何将我的 MAUI 应用程序连接到生产环境中的 Firestore 数据库? - How do I connect my MAUI app to a Firestore database in production? Firestore:如何更新 email 并将其作为单个批处理操作存储在我的 Firestore 集合中? - Firestore: How do I update email and store it in my firestore collection as a single batch operation? 如何为 Firestore 创建大量示例数据? - How do I create a lot of sample data for firestore? 如果我的后端是 firebase firestore,我如何在我的 react js 应用程序中使用 JWT - How do i use JWT in my react js app, if my backend is firebase firestore 如何检索作为文档放置在 Firebase Cloud Firestore 中的 UID - How do I retrieve the UID's that I have placed as documents in my Firebase Cloud Firestore 如何使用连接到 Firebase Firestore 的 Flutter 管理导航路线表 - How do I manage navigation routes table with Flutter connected to Firebase Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM