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

Mariano Bordon
Mariano Bordon
11,816 Points

RSVP from JS to React

Hi everyone!

I am trying to build the RSVP website from a JavaScript course to React after seeing the new React course. I have some problems inserting the <li> element inside the <ul> in a const called MainDiv.

    {this.state.invitees.map( invitees =>
      <Invited 
        name={invitees.invited}
        id={invitees.id}
        key={invitees.id.toString()}
      />
    )}

If I insert this into the MainDiv I get an error. If i do outside when I render class App I see it but outside the <ul>. I cant get it work inside the <ul> like doing this code:

const MainDiv = () => { return ( <div className="main"> <p>Invitees</p> <ul> {this.state.invitees.map( invitees => <Invited name={invitees.invited} id={invitees.id} key={invitees.id.toString()} /> )} </ul> </div> ) }

It says that cannot read the property of state.

Sorry about my english!

1 Answer

Zack Jackson
Zack Jackson
30,220 Points

Have you been to the React docs?

This looks like what you need to get this done: https://reactjs.org/docs/lists-and-keys.html