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

371
Vistas
What is correct way to call function inside setState(useState) hooks

I want to update state at real time and call function inside setState but i am getting error.

onClick={() => setDetails(prevState => ({...prevState,id: product.orderId,status: 'processing'}) => updateStatus() )}

enter image description here

Can someone tell me correct syntax and expression

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It seems you are using hooks. You can't call a function in setState like in class components. You need to watch it through useEffect.

React.useEffect(() => {
  updateStatus() 
}, [state.id, state.status])
about 4 years ago · Juan Pablo Isaza Denunciar

0

the function created using useState hook doest have a second argument. it will not support call back function after updating the state. it was only there in the setState function which is used in class components.

You can use useEffect instead

useEffect(()=> {
   updateStatus()
}, [details])

   return (
     ...
    onClick={() => setDetails(prevState => ({...prevState,id: product.orderId,status: 'processing'}))}
     ...
    )

in this way, on every setDetails update it will call useEffect and then updateStatus

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