reduxjs / redux-essentials-example-app

Example app for the Redux Essentials tutorial
https://redux.js.org/tutorials/essentials/part-1-overview-concepts
304 stars 811 forks source link

Uncaught TypeError: Cannot read properties of undefined (reading 'map') #41

Closed Pitfall-cmd closed 2 years ago

Pitfall-cmd commented 2 years ago
import React from 'react'
import { useSelector } from 'react-redux'

export const PostsList = () => {
  const posts = useSelector(state=> state.posts)
  console.log(posts) //undefined
  //console.log(123456)
  const renderedPosts = posts.map((post) => ( //Uncaught TypeError: Cannot read properties of undefined (reading 'map')
    <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>
  )
}

sorry anybody can help me !!