Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda