繁体   English   中英

TypeError: .map is not a function 不明白出了什么问题

[英]TypeError: .map is not a function don't understand what's wrong

我不明白为什么这个组件不起作用这里是 img 的链接“因为不知何故我无法直接发布图像 [1]: https : //i.stack.imgur.com/Ax7im.png感谢您的任何帮助在这里你有代码:

import React from 'react';
import ReactDOM from 'react-dom';
import Postitem from "./Postitem";

const Postlist=(post,title)=>{

return (
<div>
         <h1 style={{textAlign: 'center'}}>{title}</h1>
{post.map((post) =>
 <Postitem post={post} key={post.id}/>)};
</div>
 
)};
export default Postlist;
      

React 函数组件只接受一个参数,即一个包含所有道具的对象。 假设您在渲染时将post prop 作为数组传递,将函数声明修复为此将起作用:

const Postlist=({post,title})=>{
  // component body here, as above
}

检查,这个组件的“post”变量中有什么。 如果你使用“post.map”函数,那么它必须是一个数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM