M
M
Martian_o2019-04-22 16:47:03
React
Martian_o, 2019-04-22 16:47:03

React, can't render element after axios get request?

5cbdc55b6b4e0655989566.png

{this.state.cinemas.map(cinema => (
          <ListItemCinema
            mall={cinema.attributes.mall}
            title={cinema.attributes.title}
            subway={
              cinema.attributes.subway[0] === "undefined"
                ? null
                : cinema.attributes.subway[0].name
            }
            labels={cinema.attributes.labels}
            key={cinema.id}
            shortTitle={cinema.attributes.shortTitle}
          />
        ))}

how can i display all the elements if there is a subway array in some objects

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-04-22
@Martian_o

There is nothing stopping you from passing the cinema object to the component as a whole:

const ListItemCinema = ({ cinema }) => {
  const { subway, shortTitle, labels, title, mail } = cinema.attributes;
  
  /* some code */  

  return (
    <div>
      {/* some code */}
      <ul>
        {subway.map(station => <li key={station.name}>{station.name}</li>)}
      </ul>
    </div>
  );
}

K
Kappy, 2019-04-22
@KappyJS

{this.state.cinemas.map((cinema,num) => (
      <ListItemCinema
        mall={cinema.attributes.mall}
        title={cinema.attributes.title}
        subway={
          cinema.attributes.subway[num] === "undefined"
            ? null
            : cinema.attributes.subway[num].name
        }
        labels={cinema.attributes.labels}
        key={cinema.id}
        shortTitle={cinema.attributes.shortTitle}
      />
    ))}

If you are talking about it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question