0

So I have a table, like so:

render() {
    return (
      <table id="customers">
  {/* <% if(data.length){ 
    for(var i = 0;i < data.length;i++) { %> */}
      <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Message</th>
      </tr>
      <tr>
        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td>Germany</td>
      </tr>
    </table>
    );
  }

I am able to pass the data through to the front end, however, I want to be able to loop through there data in the table. I know this is possible in ejs, but react is totally diff.

thanks 4 the help :)

1

1 Answer 1

1

You can try this.

   render() {
        return (
          <table id="customers">
     ​<tr>
           ​<th>Name</th>
           ​<th>Email</th>
           ​<th>Message</th>
         ​</tr>
      {data.length? data.map((item, key)=>{
                return <tr>
            <td>{item.name}</td>
            <td>{item.email}</td>
            <td>{item.message}</td>
          </tr>
            }):""}
    
        </table>
        );
      }
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.