![](/img/trans.png)
[英]Don't Understand what's wrong with my Code, FreeCodeCamp (NodeJS)
[英]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.