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

105
Views
How to get value of updated state immediatly in useEffect

In the following I am updating the value of a state and then trying to use it inside useEffect only but cannot get the value of the updated state can anyone help me regarding how can i get updated state immediately inside useEffect only

Thank you

    useEffect(() => {
                dispatch(setSecondaryInvName(barcodeData))
                console.log("secondaryInventoryName == ", secondaryInventoryName)
            }
    })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you shouldn't and you cant.

first use useEffect like componentDidMount with []:

useEffect(() => {
    dispatch(setSecondaryInvName(barcodeData))
}, [])

then you should use useEffect like componentDidUpdate with [secondaryInventoryName]:

useEffect(() => {
    console.log("secondaryInventoryName == ", secondaryInventoryName)
}, [secondaryInventoryName])
about 4 years ago · Juan Pablo Isaza Report

0

You can't get immediately updated value in useEffect instead of you have to make a dependency in useEffect whenever its value will update it will trigger. Like:

useEffect(() => {
            dispatch(setSecondaryInvName(barcodeData))
         
        }
},[])
 useEffect(() => {
            
            console.log("secondaryInventoryName == ", secondaryInventoryName)
        }
},[secondaryInventoryName])
about 4 years ago · Juan Pablo Isaza Report
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!