Problem in Reactjs Typer Error: Cannot ready property 'map' of undefined

Hello I have ran into another error on this Reactjs project. displaying a TypeError: Cannot read property ‘map’ of undefined. on line 9 In the code /src/components/users/UserList.jsx If anyone could help me understand how I can fix this I greatly appreciate it. This is a project that just Reactjs for now but I will soon add Golang to it.

The code is in the github


But I want to post the part of the app that I believe is the problem here.

`import React from ‘react’;
import User from ‘./User.jsx’;
import PropTypes from ‘prop-types’;

class UserList extends React.Component{
render(){
return (

    {
    this.props.users.map( user =>{
    return (
    )
    })
    }

)
}
}

UserList.propTypes = {
users: PropTypes.array.isRequired
}

export default UserList`

Usually that means that the input to map is not an array. Your code here looks good and proptypes should give you an error if it’s not.

Have you tried logging typeof(users) to see if it is an array?

says undefined. I am not getting a response I believe it has something to do with the state of UserList and App.jsx but I do not know how to change it.

Are you passing users as a prop in the UserList parent component?

Also, in my comment above, you should be checking (typeof(this.props.users)) rather than simply users.

UserList doesn’t have state of it’s onw in your example, only props passed from parent component, presumably App.jsx

Try passing the prop explicitly instead of using the spread operator just to see if that data is intact.

I just ran your repo and could not reproduce this. I got propType warnings, but no TypeError message.

Can you run me through the step to repro this?

I solved the problem this is the new code on github https://github.com/lashleykeith/GoAndReactjs