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

174
Visualizações
how to call a function after completion of setting a state variable of a functional component in reactjs

I have a state variable where it is continuously changing and after the final state change I have to call a function which removes duplicate from final state variable.

while I am setting state variable, I am using prevstate to merge the present state value

code is below

const setevent = async(events) =>{
    await setevent((prevstate) => [...prevstate,...events])
}

I have to call a function using final event variable as props.

how can I do this?

actually I have seen a approach where after completing the setstate it is like below

const setevent = async(event) =>{
    await setevent(event,() => {
      //calling the function which I need
      getunique(event)
  })
}

but I cant make it work because I am already using prevState.

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use useEffect and monitor your events changing state , when it reached its condition then you can trigger your function like this .

useEffect(() => {
    if(myCondition)
      getunique(something)
  },[events]);
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