Using Async/Await in Firebase

混江龙づ霸主 提交于 2020-01-06 04:37:10

问题


I'm making a call to firestore with an array of member ids - looking to get back the photoURL property for each and render via jsx. I checked memberAvatars and it's returning fine, but I get this error:

Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.

Here is the code I'm using. It is meant to render each cell in an ant table using their render prop.

 async getMemberAvatars(members) {
    let memberAvatars = [];
    const urls = members.map(async userId => {
      const doc = await db
        .collection("users")
        .doc(userId)
        .get();
      memberAvatars.push(doc.data().photoURL);
    });
    await Promise.all(urls);
    let jsx = memberAvatars.map(url => <Avatar src={url} />);
    return jsx;
  }

来源:https://stackoverflow.com/questions/59473492/using-async-await-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!