0

I can't get the following to work in React's render()

<table>
  <tbody>
    ...
    { this.state.data.map( (entry, index) => 
      <tr>{ Object.values(entry).forEach( e => <td>{e}</td> )}</tr> 
    )}
  </tbody>
</table>

However, when I replace <td>{e}</td> with console.log(e) I see what I expect to render. In fact, no regular html element would render inside the forEach method either. What is the common way of doing this in React?

1 Answer 1

5

.forEach doesn't return anything, but .map does. If you change

Object.values(entry).forEach( e => <td>{e}</td>

to

Object.values(entry).map( e => <td>{e}</td>

that should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.