diff --git a/part2/countries/src/App.js b/part2/countries/src/App.js index 3c7b100..6949c34 100644 --- a/part2/countries/src/App.js +++ b/part2/countries/src/App.js @@ -1,49 +1,12 @@ import { useState, useEffect } from "react"; import axios from "axios"; +import Countries from "./components/Countries"; const App = () => { const [query, setQuery] = useState(""); const [countries, setCountries] = useState([]); const [showedCountries, setShowedCountries] = useState([]); - const CountryData = ({ country }) => { - return ( -
-

{country.name.official}

-
Capital: {country.capital}
-
Area: {country.area} km²
-

Languages:

- - {`${country.name.common} -
- ); - }; - - const Countries = ({ showedCountries }) => { - const [country, setCountry] = useState(""); - if (showedCountries.length === 1) { - return ; - } else if (showedCountries.length <= 10) { - return ( -
- {showedCountries.map((country) => ( -
- {country.name.common}{" "} - -
- ))} - {country && } -
- ); - } else if (showedCountries.length > 10) { - return
Too many matches, specify another filter
; - } - }; - useEffect(() => { axios.get("https://restcountries.com/v3.1/all").then((response) => { setCountries(response.data); diff --git a/part2/countries/src/components/Countries.js b/part2/countries/src/components/Countries.js new file mode 100644 index 0000000..e9c3492 --- /dev/null +++ b/part2/countries/src/components/Countries.js @@ -0,0 +1,25 @@ +import { useState } from "react"; +import CountryData from "./CountryData"; + +const Countries = ({ showedCountries }) => { + const [country, setCountry] = useState(""); + if (showedCountries.length === 1) { + return ; + } else if (showedCountries.length <= 10) { + return ( +
+ {showedCountries.map((country) => ( +
+ {country.name.common}{" "} + +
+ ))} + {country && } +
+ ); + } else if (showedCountries.length > 10) { + return
Too many matches, specify another filter
; + } +}; + +export default Countries; diff --git a/part2/countries/src/components/CountryData.js b/part2/countries/src/components/CountryData.js new file mode 100644 index 0000000..c088917 --- /dev/null +++ b/part2/countries/src/components/CountryData.js @@ -0,0 +1,18 @@ +const CountryData = ({ country }) => { + return ( +
+

{country.name.official}

+
Capital: {country.capital}
+
Area: {country.area} km²
+

Languages:

+
    + {Object.values(country.languages).map((language) => ( +
  • {language}
  • + ))} +
+ {`${country.name.common} +
+ ); +}; + +export default CountryData;