this will help setState is asynchronous which means the state isn't updated yet by the time you call this.createGrid(); You can call createGrid after the state has been updated by passing in the function as the callback argument
wish help you to fix your issue If you want to perform any asynchronous requests, I suggest you perform them in the componentDidMount lifecycle method. This is the suggested path based on the Reactjs documentation for componentDidMount.
To fix this issue A few things here. Your state is not changing because the function in which you call setState has a different value for this than you're expecting. If you check the console, you should see an error indicating that this.setState is not a function. You need to change the following: