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

97
Visualizações
How to update multiple dependent setStates in same function using Hooks in functional component

I have a Parent and Child Components. I pass a prop from the Child component into the a Parent Method that acts on multiple dispatches from a useReducer Hook using the following code

in Child

onPress={()=>props.clickTile(props.id)

while receiving the props.id inside the Parent method

in Parent

function clickTile(id)

this is needed to access dynamically created buttons and be able to reach their related state.

in Parent

            if (tileOne !== null) {

               setTileTwo(selectTile); //setState
               //code..

               if (tileTwo !== null) {// doesn't update until another click causing halt
                   //code...
               }

            }

however inside this method I have to call multiple conditionals as well as expressions using the same useReducer state causing issues due to the state not updating until the next click.

for more on passing from Child to Parent see my previous related question

PS. please suggest a better title.

about 4 years ago · Juan Pablo Isaza
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