【发布时间】:2021-12-10 04:20:48
【问题描述】:
我是 react 新手,所以我尝试遵循 react redux 教程并收到此错误 - TypeError: Cannot read properties of undefined (reading 'map')
如果有人能帮忙谢谢你,我真的很感激!
下面是我的代码
import React, {useState} from 'react'
import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom'
export const PostsList = () => {
const posts = useSelector(state => state.posts)
const renderedPosts = posts.map(posts => (
<article className="post-excerpt" key={posts.id}>
<h3>{posts.title}</h3>
<p className="post-content">{posts.content.substring(0, 100)}</p>
<Link to={`/posts/${posts.id}`} className="button muted-button">
View Post
</Link>
</article>
))
return (
<section className="posts-list">
<h2>Posts</h2>
{renderedPosts}
</section>
)
}
【问题讨论】:
标签: reactjs function react-redux