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

121
Views
los datos de axios no se obtienen en la primera ejecución

Estoy tratando de obtener y mostrar datos de OpenWeather api, pero en la primera ejecución, el objeto currentWeather estará vacío y luego, al volver a cargar, se recuperarán los datos. Aquí está el código

 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;

cualquier ayuda sería apreciada gracias

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!