Created
April 28, 2023 17:27
-
-
Save kkhanal18/4e4132cc145de12290a576be5363aa83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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