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

120
Vistas
How can I read the data directly after dispatch action has mutated the state in react

I just can't seem to grasp the concept of waiting state to be updated in react functional component and I have a little problem regarding dispatching actions using reducers in react. I want to trigger error popUp once the user type the wrong text in input field. It works fine but the state is legging behind one step. Error is variable from state that is manipulated from within react reducer.

//here is my error state from reducer which I want to update immediately

const [{error}, dispatch] = useStateValue();

//triggering dispatch for changing states in reducers

const useTicket = (e) => {
    e.preventDefault();
    dispatch({
    type: 'ADD_TICKETS',
    item : ticket,
    })
    console.log(`error is ${error}`);
    if(error !== 0 && error !== ''){
        setTimer();
    }
    setTicket({name: ''})
}

//this one is for showing popups

    const setTimer = () => {
    if(error !== '0' && error !== ''){
    setPopUp((popUp) => popUp = true);
    setTimeout(() => {
        setPopUp((popUp) => !popUp);

    }, 3000)
    }

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