Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
axios data is not fetched on first run

I am trying to fetch and display data from OpenWeather api but on first run the currentWeather object will be empty then on reload the data is fetched. Here is the code

import { Box, CssBaseline } from "@mui/material";
import { useEffect, useState } from "react";
import CardList from "./components/CardList";
import axios from 'axios'


function App() {
  const [currentWeather, setCurrentWeather] = useState({})

  useEffect(() => {
    const getCurrentWeather = (city) => {
      axios.get(`https://api.openweathermap.org/data/2.5/weather? q=${city}&appid=${API_KEY}&units=metric`)
      .then(res =>
        setCurrentWeather(res.data)
        )
      .catch(err =>
        console.log(err)
        )
      .finally(() => {
        console.log(currentWeather)
       }
       )
    }
    getCurrentWeather('Bulawayo')
}, [])



return (
  <Box sx={{
    p: 4,
    backgroundColor: "#f3f6fa",
  }}>
    <CssBaseline />
    <CardList currentWeather={currentWeather} />
  </Box>
);
}

export default App;

any help would be appreciated thank u

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!