This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
fullstack-open/part2/countries/src/components/Countries.js
2023-03-24 11:21:04 +02:00

26 lines
766 B
JavaScript

import { useState } from "react";
import CountryData from "./CountryData";
const Countries = ({ showedCountries }) => {
const [country, setCountry] = useState("");
if (showedCountries.length === 1) {
return <CountryData country={showedCountries[0]} />;
} else if (showedCountries.length <= 10) {
return (
<div>
{showedCountries.map((country) => (
<div key={country.cca3}>
{country.name.common}{" "}
<button onClick={() => setCountry(country)}>show</button>
</div>
))}
{country && <CountryData country={country} />}
</div>
);
} else if (showedCountries.length > 10) {
return <div>Too many matches, specify another filter</div>;
}
};
export default Countries;