diff --git a/part2/2.12-2.14/src/App.js b/part2/2.12-2.14/src/App.js index e94df42..27148bf 100644 --- a/part2/2.12-2.14/src/App.js +++ b/part2/2.12-2.14/src/App.js @@ -8,6 +8,7 @@ const App = () => { const [newSearch, setNewSerach] = useState('') const [CountryList, setCountryList] = useState([]) const [ResultList, setResultList] = useState([]) + const [WeatherData, setWeatherdata] = useState([]) useEffect(() => { axios @@ -17,8 +18,22 @@ const App = () => { }) }, []) + useEffect(() => { + console.log(ResultList) + if (ResultList.length > 0 ) { + const capital = ResultList[0].capital + const apistring = `http://api.weatherstack.com/current?access_key=9482b8f61c984f8e1988759e020d133e&query=${capital}` + console.log(capital, apistring) + axios + .get(apistring) + .then(response => { + setWeatherdata(response.data) + }) + console.log(WeatherData) + } + }, [ResultList]) + const clickHandler = (index) => { - console.log(index) const newresult = ResultList newresult[index].Show = !newresult[index].Show setResultList([...newresult]) @@ -31,14 +46,14 @@ const App = () => { useEffect(() => { const sfilter = CountryList.filter(country => country.name.toLowerCase().includes(newSearch.toLowerCase())) const filter = sfilter.map(item => ({...item,Show:false})) - setResultList(filter) + setResultList([...filter]) }, [newSearch, CountryList]) return (
{data.name}
- {show === true &&
Capital: {data.capital}
-
+
Population: {data.population}
Temperature: {weather.current.temperature} Celcius
+Wind: {weather.current.wind_speed} mph {weather.current.wind_degree} {weather.current.wind_dir}
+