reactjs - Firebase 错误:对象作为 React 子对象无效(发现:对象与键 {seconds,nanoseconds})
问题描述
首先,我从 firebase 查询我的数据:
useEffect(() => {
if (user) {
async function fetchData() {
const request = await db
.collection("users")
.doc(user)
.collection("notifications")
.onSnapshot((snapshot) =>
setNotifications(
snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id }))
)
);
}
fetchData();
} else {
setNotifications([]);
}
}, [user]);
查询返回:
现在,当我尝试渲染数据时:
<div className="notifications">
{notifications.map((notification) => (
<NotificationContainer
notificationType={notification.notificationType}
notificationFrom={notification.notificationFrom}
timestamp={notification.timestamp}
linkId={notification.linkId}
/>
))}
当我尝试在页面上呈现数据时,出现以下错误:
Error: Objects are not valid as a React child (found: object with keys {seconds, nanoseconds}). If you meant to render a collection of children, use an array instead.
知道我做错了什么吗?notifications
我认为在我从数组中读取数据的那一天可能有问题
解决方案
所以我使用了timestamp
firebase字段。当我尝试渲染它时,我所说的讨厌的错误就会弹出。
时间戳不是一个字符串,很可能是一个对象。
推荐阅读
- laravel - 如何在 laravel 中为经过身份验证或未经身份验证的用户创建单个端点?
- google-apps-script - 将各种数据格式传递到 Google 表格图表
- vuejs2 - 如何动态设置类名?
- javascript - 创建带参数的 Promise
- java - 当从另一个类调用使用它的方法时,为什么自动装配对象为空?
- button - 角度日期选择器未显示在 mat-menu 中
- swift - 在 Swift 中使用 available
- python - 无法使用 pip install spacy 安装 spacy
- javascript - 如何复制 JavaScript 生成的文本?
- pandas - 分解时间间隔并将它们分配给相应的时间