Skip to content
Advertisement

React setState not updating

JavaScript

In this code in the else block, when the setState function is called, the state doesnot change

Note: Even if it is asynchronous it doesn’t change it all after a long time

Could this problem be because of the ES6 destructuring of the state

EDIT

I logged and checked with a callback and still the state remains unchanged

JavaScript

Advertisement

Answer

You can always copy the state in local var, make changes and set again the state. Something like:

JavaScript
Advertisement