feedPosts数组迭代了3次,其中帖子是从存储中提取的,虽然我已经添加了关键prop到postComponent,但我得到了错误的添加一个关键
const Home = ()=>{
const navigate = useNavigate();
const dispatch = useDispatch();
const authToken = Cookies.get("jwtToken");
const feedPosts = useSelector(state => state.feedPosts.posts);
useEffect(()=>{
axios.get("http://localhost:8080/posts",{
headers:{
'authorization': authToken
}}).then((posts)=>{
dispatch(setFeedPosts({posts: posts.data}))
})
},[]);
return(
<div className="homepage">
<div className="post-container">
{feedPosts.map((post)=>
<PostComponent key={post.id}
firstName={post.firstName}
lastName={post.lastName}
userId={post.userId}
content={post.content}
/>
)}
</div>
</div>
)
}
1条答案
按热度按时间zbsbpyhn1#
}; export default Home;确保文章ID是唯一的