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

116
Vistas
getting a parameter in react

I would like to get the "weatherdata" parameter from GetDatas() function in my h4. I have been trying for a while now, but I don't know how to do it.

function GetDatas(e){
        e.preventDefault();
        console.log(cityname)
         fetch(cityURI)
        .then(city => city.json())
        .then(citydata => {
        fetch(`http://api.openweathermap.org/data/2.5/forecast?lat=${citydata[0].lat}&lon=${citydata[0].lon}&appid=${key}`)
            .then(weatherdata => weatherdata.json())
            .then(weatherdata => {
                return weatherdata
            })
        });
    }

       return (
        <div className="cityinput">
            <form onSubmit={() => {GetDatas();}}>
                <label >City name</label>
            <input type="text" onChange={(e) => SetCityname(e.target.value)} />
            </form>
            <div>
                <h4>Name: {weatherdata.name}</h4>
            </div>
        </div>
    );
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try to Store your weatherData response in a state variable. And use that state variable to conditionally render your weatherData.name in your JSX. i.e., {weatherData && weatherData.name && <h4>{weatherData.name}</h4>}

about 4 years ago · Juan Pablo Isaza Denunciar
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