Unhandled Rejection (TypeError): Cannot read property 'map' of undefined when doing React tutorial

Unhandled Rejection (TypeError): Cannot read property 'map' of undefined when doing React tutorial

Doing a Hacker News Clone tutorial in React and Next.js, but I'm stumbling into a problem.&nbsp;<strong>I have read other questions that are dealing with the same error, but the solutions offered don't work for me.</strong>&nbsp;Here is the code:

Doing a Hacker News Clone tutorial in React and Next.js, but I'm stumbling into a problem. I have read other questions that are dealing with the same error, but the solutions offered don't work for me. Here is the code:

import React from 'react';

const StoryList = ({ stories }) => ( <div> {stories.map(story => ( <h3 key={story.id}>{story.title}</h3> ))} </div> );

export default StoryList;

The error is specifically at line 4 of that, on the first div tag.

Here is my index page:

import React from 'react';
import fetch from 'isomorphic-fetch';
import Error from 'next/error';

import StoryList from '../components/StoryList';

class Index extends React.Component { static async getInitialProps() { let stories;

    try {
        const response = await fetch(
            'https://node-hnapi.herokuapp.com/news?page=1'
        );
        stories = await response.json();
    } catch (err) {
        console.log(err);
        stories = []
    }

    return { stories };
}

render() {
    const { stories } = this.props;

    if (stories.length === 0) {
        return &lt;Error statusCode={503} /&gt;;
    }

    return (
        &lt;div&gt;
            &lt;h1&gt;Hacker News Clone&lt;/h1&gt;
            &lt;StoryList storeis={stories} /&gt;
        &lt;/div&gt;
    )
}

}

export default Index;


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project

ReactJS vs Angular vs Vue: Best Javascript Framework For Your Project. This video covers the key differences between ReactJS, Angular and Vue with respect to the following: Use case, Performance, Data binding, Scripting language, Testing, Community support, Growth curve

What is JavaScript – All You Need To Know About JavaScript

In this article on what is JavaScript, we will learn the basic concepts of JavaScript.