Reputation: 121
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 :)
Upvotes: 0
Views: 31
Reputation: 688
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>
);
}
Upvotes: 1