V
V
vladislav31012021-03-22 23:29:26
React
vladislav3101, 2021-03-22 23:29:26

How to fix error when rendering components in map?

I wrote components for a table, and I'm trying to display in the map functions, but I get this error:


Objects are not valid as a React child (found: object with keys {scope, children}). If you meant to render a collection of children, use an array instead.


Code
// Data: [{id: 1, name: 'Product-1', price: 2,}, {id: 2, name: 'Product-2', price: 3}]
return (
    <Table>
      <TableHead columns={columns} />
      <TableBody>
        {data.map((item) => {
          return (
              <TableRow>
                <TableHeading scope="row">{item.id}</TableHeading>
                <TableCell>{item.name}</TableCell>
                <TableCell>{item.price}</TableCell>
              </TableRow>
          );
        })}
      </TableBody>
    </Table>
  );
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vladislav3101, 2021-03-23
@vladislav3101

found an error, it was not here at all. In the TableHeading component, I forgot to specify the {children} destructuring. Sorry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question