0

I am trying to learn react and try to make a simple react app. It has some bugs that I could not fixed them like to get the weather dat submit button needs to clicked twice. At least, I was getting the weather when I click twice:) on the local. The main problem start when I upload it netlify for deploying https://myweatherapp12.netlify.app This is the link if you want to check it. When I submit the form, it does not fetch the data from weather API. I add the code that handle the onSubmit. Thanks for help..

function updateInput(event) {
    event.preventDefault();
    setcity1(city);
    setcountry1(country);
     const API_KEY = "49354479869ae18d7dfbe48bbd9eced7";
    fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city1},$Turkey&appid=${API_KEY}`).then((res) => { if (res.status >= 200 && res.status < 299) { return res.json() } else { sethata(true) }}).then((data) => setweatherResponse(data));
    
    setgoster(true);
    console.log(city1);
    console.log(country1)
    
  • I'm almost certain if you were checking the network tab in the browser's dev tools you'd have seen 1 request made per click. React state updates are processed asynchronously so when you enqueue state updates and then console log the sate immediately after you are logging the ***current*** state, not what the state will be for the ***next*** render cycle. – Drew Reese Jul 13 '21 at 23:27
  • Thanks you so much for your answer. You inspire me to check the console. It gives error . I copy paste error and figure out that. There is a problem with api call permissions. First I need to check Api url it needs to start with https not http second need to ad to index.html head tag – OZLEM CITCI Jul 14 '21 at 04:15

0 Answers0