Javascript TypeError:comments.map不是React中的函数
映射时出现以下错误:TypeError:comments.map不是函数。请帮助我解决以下错误。我哪里出错了,它作为一个组件工作得很好,但当我将rendercommons转换为函数时,它返回以下错误 详细信息文件:Javascript TypeError:comments.map不是React中的函数,javascript,html,reactjs,Javascript,Html,Reactjs,映射时出现以下错误:TypeError:comments.map不是函数。请帮助我解决以下错误。我哪里出错了,它作为一个组件工作得很好,但当我将rendercommons转换为函数时,它返回以下错误 详细信息文件: 从“React”导入React; 从“reactstrap”导入{Card,CardMg,CardBody,CardTitle,CardText}; 函数renderish({dish}){ 返回( {" "} {dish.name}{”“} {dish.description}{
从“React”导入React;
从“reactstrap”导入{Card,CardMg,CardBody,CardTitle,CardText};
函数renderish({dish}){
返回(
{" "}
{dish.name}{”“}
{dish.description}{”“}
{" "}
);
}
函数RenderComments(注释){
if(注释!=null){
返回(
评论{“}
{" "}
{comments.map(comment=>{
返回(
-
{comment.comment}{''}
{" "}
--{comment.author},{'}
{Intl.DateTimeFormat(“en US”{
年份:“数字”,
月:“短”,
日期:“两位数”
}).format()}{“}
{“}
);
})}{" "}
{“}
);
}否则{
返回;
}
}
const dishdestail=props=>{
if(props.dish!=null){
返回(
{" "}
{" "}
{" "}
{" "}
{" "}
{" "}
);
}否则{
返回;
}
};
导出默认细节
功能组件的默认参数名为props
,可以对其进行分解以获得传递的props,如:
function RenderComments({comments}) {
....
“评论”里到底是什么?不相关,但奇怪的格式使其难以阅读。