Answer the question
In order to leave comments, you need to log in
How to fix the code so that when you press the ok button, the card card disappears?
How to fix the code so that when you press the ok button, the card card disappears?
const Countries = ({data}) => {
const [showCard, setShowCard] = useState('none');
const ShowOnClick = (cardId) =>{
setShowCard(cardId)
}
const CloseOnClick = () => {
setShowCard('none')
}
if (!data) {
return (
<h1>Loading...</h1>
)
}
return (
<table className="table">
<thead>
<tr>
<th>№</th>
<th>Country</th>
<th>Total Confirmed</th>
</tr>
</thead>
<tbody>
{data.map((country, index) => (
<tr onClick={() => ShowOnClick(index)} key={index}>
<td>{index + 1}</td>
<td>{country.Country}</td>
<td>{country.TotalConfirmed}</td>
<td>
<div className="card" style={{display: showCard === index ? 'grid' : 'none'}}>
<div className="country">{country.Country}</div>
<div className="stat">
<div className="img-heart"></div>
<div>Total Confirmed</div>
<div className="card-stat">{country.TotalConfirmed}</div>
</div>
<div className="stat">
<div className="img-skull"></div>
<div>Total Deaths</div>
<div className="card-stat">{country.TotalDeaths}</div>
</div>
<div className="stat">
<div className="img-plus"></div>
<div>Total Recovered</div>
<div className="card-stat">{country.TotalRecovered}</div>
</div>
<button onClick={CloseOnClick} className="btn">OK</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
)
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question