Skip to content

Commit

Permalink
improve fetching in weather app
Browse files Browse the repository at this point in the history
  • Loading branch information
No0ne003 committed May 17, 2024
1 parent 46f0906 commit a802095
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/pages/Weather-app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { FaMapPin, FaWind } from "react-icons/fa6";
import { WiHumidity } from "react-icons/wi";

const WeatherApp = () => {
const [search, setSearch] = useState("");
const [search, setSearch] = useState("marrakech");
const [input, setInput] = useState("");
const [loading, setLoading] = useState(false);
const [weatherData, setWeatherData] = useState(null);

Expand All @@ -30,7 +31,7 @@ const WeatherApp = () => {
}

function handleSearch() {
fetchWeatherData(search);
setSearch(input);
}

function getCurrentDate() {
Expand All @@ -43,18 +44,14 @@ const WeatherApp = () => {
}

useEffect(() => {
fetchWeatherData("marrakech");
}, []);
fetchWeatherData(search);
}, [search]);

console.log(weatherData);

return (
<div className="container flex flex-col justify-start items-center gap-5 py-10 w-fit bg-secondary/40 aspect-[3/2]">
<Search
search={search}
setSearch={setSearch}
handleSearch={handleSearch}
/>
<Search search={input} setSearch={setInput} handleSearch={handleSearch} />
{loading ? (
<LoadingMsg />
) : weatherData?.cod === "404" && weatherData?.message ? (
Expand Down

0 comments on commit a802095

Please sign in to comment.