I have just found that in react this.setState() function in any component is asynchronous or is called after the completion of the function that it was called i
this.setState()
You can use the following wrap to make sync call
this.setState((state =>{ return{ something } })