Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

TypeError: Cannot read property 'map' of undefined

When I enter the code as he says on the video I get the error message described in the title...

In GuestList.js const GuestList = (props) => <ul> {props.guests.map((guest, index) => <li className="responded"> <span>Iver</span> <label> <input type="checkbox" checked /> Confirmed </label> <button>edit</button> <button>remove</button> </li> )} </ul>

GuestList.propTypes = { guests: PropTypes.array.isRequired }

In App.js => <GuestList guests={this.state.guests} />

However, if I change the propTypes to say guest it works...

In GuestList.js const GuestList = (props) => <ul> {props.guests.map((guest, index) => <li className="responded"> <span>Iver</span> <label> <input type="checkbox" checked /> Confirmed </label> <button>edit</button> <button>remove</button> </li> )} </ul>

GuestList.propTypes = { guests: PropTypes.array.isRequired }

In App.js => <GuestList guests={this.state.guests} />

Can someone tell me why this is happening, and why the code from the video doesn't work?

2 Answers

This is for the 'Building the GuestList' video on the React course

Ignore me I've figured it out