Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!