How to list a Graphapi response with React?

Asked

Viewed 93 times

1

I have been trying for days to create a simple list of the names of the events I receive from a request for Graphapi from Facebook. The object I receive is the following: Response

How do I make a list of event names only? for example:

John Mayer....
Popload....
Torments...
...

1 answer

1


Within that events you have an array of objects, so in your render you can have something like this:

(assuming that events is in the state as this.state.events)

render() {
  const events = this.state.events;
  const eventsItems = events ? events.data.map(
    event => (<p key={event.id}>{event.description}</p>)
  ) : [];
  return (
     <div>
        {events}
     </div>
  );
}
  • 1

    Perfect. Now it worked. I still don’t quite understand this conditional. Is this ES6? How would it look in the old syntax?

  • @Jucaesmanhoto take a look here: https://answall.com/a/4908/129 (this is previous to ES6)

  • 1

    Great! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.