Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda