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

190
Views
why my React setstate is not updating immediately?

This a my function

    onSelectAction = (x, o) => {
    var { takeActionsOptions } = this.props.main
    console.log(o, "onSelectAction")
    var tempAction=_.cloneDeep(takeActionsOptions)

    _.keys(tempAction).map(a => {
        if(a === x.processCode) {
            tempAction[a].map((b)=>{
                b.isSelected = b.id === o.id

            })
        }
        else{
            tempAction[a].map((b)=>{
                b.isSelected = b.id === 0
            })
        }
    })
    StoreActions.setState({ takeActionsOptions:tempAction});
    this.onClickTakeAction(o, x)
}

where tempAction is changing the property like the i wanted to. But when i m trying update the store... this { takeActionsOptions:tempAction} is not getting updated for the first time. After 2-3 clicks on the desired location this is getting updated. i want to update immediately in the store because there is another function which fetches data from the store and does another operation.

this is my other function which is using the take "takeActionsOptions " from store. so if that function is not updating then this function isnt working properly

    onClickTakeAction = (o, x) => {
    var { takeActionsOptions=[] } = this.props.main
    var selectedAction = takeActionsOptions[x.processCode].find(a => a.isSelected)
    if (selectedAction.id === 0) {
        hydro.msg.info("Please select an option.")
        return;
    }
    var tempAction=_.cloneDeep(takeActionsOptions)
    _.keys(tempAction).map(a => {
        tempAction[a].map((b)=>{
            b.isSelected = b.id === 0
        })
    })
    this.setState({takeActionsOptions:tempAction})

    switch (selectedAction.id) {
        case 1:
            var userName = somecode.userName;
            if (userName.toUpperCase() === x.userName.toUpperCase()) {
                Actions.deleteSelectedProcess(x);
            }
            else {
                somecode.info("Not your Process")
            }
            break;
        case 2:
            Action.downloadLogs(x);
            break;
       
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var tempAction=_.cloneDeep(takeActionsOptions)

What the cloneDeep function is doing here? If it does any API calling/Getting data from the server, you need to wait for a moment to get the data. Meanwhile, you can disable the button and show some loaders for interactivity.

If you're using the loadash to deep copy the object, up to my knowledge loadash functions, takes a long time to complete based on the CPU or object you are trying to copy. So try to wait for a minute and check whether it's updating or not. If it is updating, then you should disable the button until then.

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!