title: Uncaught TypeError: Cannot read properties of undefined (reading 'length')
body: <p>I am developing a react app, but i am facing this error-&gt; &quot;Uncaught TypeError: Cannot read properties of undefined (reading 'length')&quot;. how to fix this?
  my code is:</p>
  <pre><code>import React from &quot;react&quot;;
  import { Grid, CircularProgress } from &quot;@material-ui/core&quot;;
  import Post from &quot;./Post/Post&quot;;
  import useStyles from &quot;./styles&quot;;
  import { useSelector } from &quot;react-redux&quot;;
  
  const Posts = () =&gt; {
    const posts = useSelector((state) =&gt; state.Posts);
    const classes = useStyles();
  
    console.log(posts);
    return (!posts.length ? &lt;CircularProgress/&gt; :(
     &lt;Grid className={classes.container} container alignItems=&quot;stretch&quot; spacing={3}&gt;
        {
          posts.map((post)=&gt; (
                &lt;Grid key={post._id} item xs={12} sm={6}&gt;
                  &lt;Post post = {post} /&gt;
                &lt;/Grid&gt;
          ))
        }
  
     &lt;/Grid&gt;
   )
    );
  };
  
  export default Posts;
  </code></pre>