Answer the question
In order to leave comments, you need to log in
Why am I getting a TypeError: Cannot read property of undefined error in React?
Good day.
I get the error `TypeError: Cannot read property 'friends' of undefined`
I can't figure out how to fix it or what I'm doing wrong.
Swears at this.
const Sidebars = (props) => {
let sidebarsElements = props.state.friends.map( friend => <SideItem name={friend.name} id={friend.id} key={friend.id}/> );
}
<nav>
<ul>
<h3>Friends</h3>
<Sidebars />
<ul>
</ul>
</nav>
let state = {
sidebarList: {
friends: [
{id: 11, name: 'Andrew'},
{id: 12, name: 'Aleksei'},
{id: 13, name: 'Mikhail'},
]
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question