<html>
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
function App() {
const hospitals = [
{
name: 'New York General Hospital',
city: 'New York',
state: 'NY',
},
{
name: 'Los Angeles Medical Center',
city: 'Los Angeles',
state: 'CA',
},
{
name: 'Chicago Memorial Hospital',
city: 'Chicago',
state: 'IL',
},
{
name: 'Houston Regional Medical',
city: 'Houston',
state: 'TX',
},
{
name: 'Philadelphia City Hospital',
city: 'Philadelphia',
state: 'PA',
},
{
name: 'Phoenix Health Center',
city: 'Phoenix',
state: 'AZ',
},
{
name: 'San Antonio Community Hospital',
city: 'San Antonio',
state: 'TX',
},
{
name: 'San Diego Medical Institute',
city: 'San Diego',
state: 'CA',
},
{
name: 'Dallas Regional Hospital',
city: 'Dallas',
state: 'TX',
},
{
name: 'San Jose Healthcare Center',
city: 'San Jose',
state: 'CA',
}
];
return (
<div className="box">
<h3>React JS Render Array of Objects</h3>
<div className="container">
{hospitals.map((hospital, index) => (
<div className="hospital" key={index}>
<h3>{hospital.name}</h3>
<p>
Location: {hospital.city}, {hospital.state}
</p>
</div>
))}
</div>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("app"));
</script>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.box {
text-align: center;
padding: 20px;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24);
margin: 0 auto;
width: 600px
}
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
justify-items: center;
}
.hospital {
background-color: #fff;
padding: 20px;
margin-bottom: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 5px;
text-align: center;
}
.hospital:last-child {
margin-bottom: 0;
}
h3 {
font-size: 20px;
color: #333;
}
p {
margin: 10px 0 0;
color: #777;
}
</style>
</body>
</html>