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

302
Views
Why is my React state not changing after the setState is called?

This problem only occurs when I run my React/Express app in development mode through a Webpack proxy. I am essentially looking to post some data to and retrieve some data from my Express server at /post. The request goes through successfully with a 200 response.

It has no problem going through the setState function, but if I print the state after it is still null despite what I set it to being a valid string. As such the data I am looking to display on screen when it is called is never displayed. As can be seen in the photo attached the data is all valid but the state ends up being set to 0.

Everything functions properly if I build it before running and do not get the response through a proxy.

Here is the entire repo and the relevant component:

  • Repo: https://github.com/The-Briel-Deal/Flight_Scanner_MUI
  • Component: https://github.com/The-Briel-Deal/Flight_Scanner_MUI/blob/main/src/components/ShowFlights.jsx
// First of all, I use state with a object as follows.
let [returnQuery, setReturnQuery] = React.useState({
    price: null,
    connections: null,
    leaves: null,
    returns: null,
    link: null
})

// Following I fetch from my express server.
async function postData() {
    const response = await fetch('/search', {
        method: "POST",
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(props.searchState)
    })
    return response.json();
}

// After this I set my state as this return value
postData().then((data) => {
    console.log(`data returned ${data.link}`)
    setReturnQuery({
            price: data.price,
            connections: data.connections,
            leaves: data.leaves,
            returns: data.returns,
            link: data.link
    })
    setTimeout(() => console.log(returnQuery), 5000)
})

What my console returns

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!