5
votes

Having a slight issue with some code that I have written, I keep getting the error:

expected an assignment or function call and instead saw an expression

I have commented where the error is happening. Not sure what the issue is however. Code is as follows:

renderBody() {
    const { bookings } = this.props;
    if (bookings.length > 0) {
        return (
            Object.keys(bookings).map(e => (
                <TableBody>
                    {Object.values(bookings[e]).forEach((value) => {
                        <TableCell>{value}</TableCell>; //<-ERROR??
                    })}
                </TableBody>
            ))
        );
    }
    return null;
}
2
Are you using curlys there where you should be using parenths to return implicitly? - sesamechicken
Please update your question with a minimal reproducible example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button). Stack Snippets support React, including JSX; here's how to do one. - T.J. Crowder
Maybe not supporting a destructuring assignment? Try removing const {bookings} - Jonas Wilms

2 Answers

4
votes

Because you are not doing anything inside forEach (no assignment, no calculation), also forEach will not return anything, use map to return the TableCell for each array entry.

Eslint will throw an error, if you write a forEach loop without any operation.

Write it like this:

{Object.values(bookings[e]).map(value => (
    <TableCell>{value}</TableCell>
))}
0
votes

You are just missing a closing ) :

 Object.values(bookings[e]).map(value => (
            <TableCell>{value}</TableCell>
  ))} // <--