2021-08-28 11:44:05 +07:00
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import Filter from './components/Filter'
|
2021-09-01 17:45:57 +07:00
|
|
|
import Country from './components/Country'
|
2021-08-28 11:44:05 +07:00
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
|
|
|
|
|
|
const [newSearch, setNewSerach] = useState('')
|
|
|
|
|
const [CountryList, setCountryList] = useState([])
|
|
|
|
|
|
|
|
|
|
const handleSearchChange =(event) => {
|
|
|
|
|
setNewSerach(event.target.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
axios
|
|
|
|
|
.get('https://restcountries.eu/rest/v2/all')
|
|
|
|
|
.then(response => {
|
|
|
|
|
setCountryList(response.data)
|
|
|
|
|
})
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filtered = CountryList.filter(country => country.name.toLowerCase().includes(newSearch.toLowerCase()))
|
|
|
|
|
console.log(newSearch.toLowerCase())
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<h2>Country</h2>
|
|
|
|
|
<Filter value={newSearch} onChange={handleSearchChange} />
|
2021-09-01 17:45:57 +07:00
|
|
|
<Country data={filtered} />
|
2021-08-28 11:44:05 +07:00
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App
|