score:0

setstate(updater[, callback])

use callback in setstate to read new value. setstate is async and you are expecting your state to be updated instantly. to make sure your state got updated, you would have to leverage on call back function passed in as second argument.

      this.setstate((state, props) => {
        return { notsaved: size }
      }, () => console.log(this.state.notsaved, 'updated notsaved')); 

detailed explanation by dan on why is setstate asynchronous?: https://github.com/facebook/react/issues/11527#issuecomment-360199710


Related Query

More Query from same tag