M
M
Marat Shakirov2021-07-22 10:32:03
React
Marat Shakirov, 2021-07-22 10:32:03

Does the example code not work?

I am making an application in React, when iterating over an array using the map method, inside it I also iterate over the object using the for loop, and inside there are also conditions. But for some reason, it swears that there is a for loop or if or switch conditions in curly braces. Although this design works outside of this component.

<TableBody>
          {cars.map((car, index) => (
            <TableRow key={index}>
              <TableCell>{`${car.mark} ${car.model}`}</TableCell>
              {
                  for (let key in car.tariffs) {
                    switch (key) {
                      case 'Стандарт':‹
                        return <TableCell>{key.year}</TableCell>;
                      case 'Комфорт':
                        return <TableCell>{key.year}</TableCell>;
                      case 'Бизнес':
                        return <TableCell>{key.year}</TableCell>;
                      case 'Комфорт+':
                        return <TableCell>{key.year}</TableCell>;
                      case 'Эконом':
                        return <TableCell>{key.year}</TableCell>;
                      case 'Минивэн':
                        return <TableCell>{key.year}</TableCell>;
                      case 'Лайт':
                        return <TableCell>{key.year}</TableCell>;
                      default:
                        return <TableCell>-</TableCell>;
                    }
                  }
              }
            </TableRow>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aagzip, 2021-07-22
@Marat20

You need to take this cycle out of jsx and call a function in jsx that returns the result of this cycle.
Or rewrite this loop using map or another iterating method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question