Skip to content

Instantly share code, notes, and snippets.

@kkhanal18
Created April 28, 2023 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkhanal18/4e4132cc145de12290a576be5363aa83 to your computer and use it in GitHub Desktop.
Save kkhanal18/4e4132cc145de12290a576be5363aa83 to your computer and use it in GitHub Desktop.
import React from 'react';
interface PopulationData {
city: string;
population: number;
}
const data: PopulationData[] = [
{
city: 'New York',
population: 8399000
},
{
city: 'Los Angeles',
population: 3999000
},
{
city: 'Chicago',
population: 2705000
}
];
function generateTable(data: PopulationData[]): JSX.Element {
return (
<table>
<thead>
<tr>
<th>City</th>
<th>Population</th>
</tr>
</thead>
<tbody>
{data.map((item) => (
<tr key={item.city}>
<td>{item.city}</td>
<td>{item.population}</td>
</tr>
))}
</tbody>
</table>
);
}
function PopulationTable(): JSX.Element {
return (
<div>
<h1>Population Table</h1>
{generateTable(data)}
</div>
);
}
export default PopulationTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment