Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda