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
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 answers
Answer question

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 Report
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!