Completed 2.12

This commit is contained in:
2021-09-01 17:45:57 +07:00
parent 614874ddd7
commit 50c2746682
5 changed files with 44 additions and 110 deletions
+42
View File
@@ -0,0 +1,42 @@
import React from 'react';
const Country = (props) => {
const filtered = props.data
return (
<div>
{filtered.length > 10 ?
'Too many matches, specific another filter' : filtered.length !== 1 ?
filtered.map(item => <CountryLongList key={item.alpha2Code} data={item}/>):
filtered.map(item => <CountryDetail key={item.alpha2Code} data={item}/>)}
</div>
)
}
const CountryLongList = ({data}) => {
return (
<div>
<p>{data.name}</p>
</div>
)
}
const CountryDetail = ({data}) => {
console.log(data)
return (
<div>
<h2>{data.name}</h2>
<p>
Capital: {data.capital}
<br />
Population: {data.population}
</p>
<h3>Languagues</h3>
<ul>
{data.languages.map(item =><li key={item.name}>{item.name}</li>)}
</ul>
<img src={data.flag} alt={data.name} width="200" />
</div>
)
}
export default Country