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

112
Views
React dispatch state not updating in the same method

I have a dispatch updating the state correctly when i was in this scenario with 2 methods ( onClick )

const sizesMeasureChoise = useSelector(getSizesMeasureChoise);


  const chooseMeasure = (measure) => {
    dispatch(setSizeMeasureChoise(measure));

  };

  const chooseType = (type) => {
    const sizeChoise = sizesMeasureChoise.description;
  }

Then i have changed and i have put everything in one method ( because i have removed the chooseType step ) and the state is not updated after the dispatch

const sizesMeasureChoise = useSelector(getSizesMeasureChoise);

  const chooseMeasure = (measure) => {
    dispatch(setSizeMeasureChoise(measure));
    const sizeChoise = sizesMeasureChoise.description;
    }

From what is depending, how can i resolve it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Once an action has been dispatched, updated values from the store will become available only on the next render.

This behavior is the same for both functional components with hooks as well as with classes that use the connect HOC.

You'll just have to modify your code so as not to expect changes immediately.

If you could describe what you want to get (rather than "how") with a minimal sample with only the relevant hooks & how data is rendered then it will be easier to suggest a solution.

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!