-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
54 lines (42 loc) · 1.45 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { useState, useEffect } from 'react';
import './App.css';
import Forecast from './components/Forecast';
import DailyForecast from './components/DailyForecast';
import Inputs from './components/Inputs';
import TemperatureDetails from './components/TemperatureDetails';
import TimeAndLocation from './components/TimeAndLocation';
import TopButtons from './components/TopButtons';
import axios from 'axios';
function App() {
const [weather, setWeather]= useState({});
const[isC, setIsC] = useState(true)
function fetchWeather(query){
axios.get(`http://api.weatherapi.com/v1/forecast.json?key=2ef2f88f2f924f0d9de172508230101&q=${query}&days=5&aqi=no&alerts=no`).then(res=>setWeather(res.data)).catch(err=>setWeather('Location Not Found!'))
}
useEffect(()=>{
fetchWeather('Kochi');
},[])
return (
<div className='mx-auto max-w-screen-md mt-4 py-5 px-32 bg-gradient-to-br from-cyan-700 to-blue-700 '>
<TopButtons fetchWeather={fetchWeather}/>
<Inputs
fetchWeather={fetchWeather}
setIsC={setIsC}
isC={isC}
/>
{weather.location?
<>
<TimeAndLocation weather={weather}/>
<TemperatureDetails weather={weather}
isC={isC}/>
<Forecast
weather={weather}
isC={isC}/>
<DailyForecast
weather={weather}
isC={isC}/>
</> : <h2 className='text-white'>{weather==='Location Not Found!' ? weather : `Fetching Data...`}</h2>}
</div>
);
}
export default App;