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

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

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