Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created March 31, 2023 17:13
Show Gist options
  • Save shameemreza/e305f0cf6bc365d8df501ef134dbb0f3 to your computer and use it in GitHub Desktop.
Save shameemreza/e305f0cf6bc365d8df501ef134dbb0f3 to your computer and use it in GitHub Desktop.
Code for the "How to Render an Array of Objects in React?" Article.
import React from "react";
function EmployeeList(props) {
const employees = props.employees;
const employeeList = employees.map((employee) => (
<tr key={employee.name}>
<td>{employee.name}</td>
<td>{employee.age}</td>
<td>{employee.position}</td>
</tr>
));
return (
<div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Position</th>
</tr>
</thead>
<tbody>{employeeList}</tbody>
</table>
</div>
);
}
export default EmployeeList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment