[英]React display data from object TypeError: value map is not a function
Getting "TypeError: value is undefined" error when trying to render the data from the value object, when I console log value the object does show.尝试从值 object 渲染数据时出现“TypeError:值未定义”错误,当我控制台日志值 object 确实显示时。
CODE代码
import React from "react";
import { useParams } from "react-router-dom";
import {
useDocumentData,
} from "react-firebase-hooks/firestore";
import firebase from "../firebase";
const firestore = firebase.firestore();
const Threads = () => {
const { threadId } = useParams();
const [value, loading, error] = useDocumentData(firestore.collection("threads").doc(threadId));
console.log(value);
return (
<div>
{value.map((thread, i) => (
<div>
<h1>{thread.title}</h1>
<p>{thread.desc}</p>
</div>
))}
</div>
);
};
export default Threads;
CONSOLE安慰
ERROR错误
The variable value is a object.变量值为 object。 Map function in JS is applicable only for arrays.
JS中的Map function仅适用于arrays。 So try this.
所以试试这个。
<div>
<h1>{value.title}</h1>
<p>{value.desc}</p>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.