我得到一个地图函数的箭头(posts.map 不是一个函数)
I get an arror for map function(posts.map is not a function)
我收到此错误,但我没有发现其中有任何问题:
posts.map is not a function
import React from 'react'
import { useSelector } from 'react-redux'
export const PostsList = () => {
const posts = useSelector(state => state.posts)
const renderedPosts = posts.map(post => (
<article className="post-excerpt" key={post.id}>
<h3>{post.title}</h3>
<p className="post-content">{post.content.substring(0, 100)}</p>
</article>
))
return (
<section className="posts-list">
<h2>Posts</h2>
{renderedPosts}
</section>
)
}
这是我的代码沙盒:https://codesandbox.io/s/wandering-darkness-6hi04d?file=/src/features/posts/PostsList.js
你的问题在文件中store.js
export default configureStore({
reducer: () => ({
posts: postsReducer
})
});
修改此文件如下:
export default configureStore({
reducer: {
posts: postsReducer
}
});
我收到此错误,但我没有发现其中有任何问题:
posts.map is not a function
import React from 'react'
import { useSelector } from 'react-redux'
export const PostsList = () => {
const posts = useSelector(state => state.posts)
const renderedPosts = posts.map(post => (
<article className="post-excerpt" key={post.id}>
<h3>{post.title}</h3>
<p className="post-content">{post.content.substring(0, 100)}</p>
</article>
))
return (
<section className="posts-list">
<h2>Posts</h2>
{renderedPosts}
</section>
)
}
这是我的代码沙盒:https://codesandbox.io/s/wandering-darkness-6hi04d?file=/src/features/posts/PostsList.js
你的问题在文件中store.js
export default configureStore({
reducer: () => ({
posts: postsReducer
})
});
修改此文件如下:
export default configureStore({
reducer: {
posts: postsReducer
}
});