title: Using this.setState in the callback of this.setState in React JS?
body: <p>Is it possible to call this.setState in the callback of this.setState? </p>
  
  <p>I am making a Roguelike Dungeon and have a setup where in the callback of this.setState a helper function is used, that calls this.setState again. My game freezes at this point.</p>
  
  <p>So I have an object in the React component that has a method to generate a random 2D array map:</p>
  
  <pre><code>this.Dungeon.Generate();
  </code></pre>
  
  <p>When the game starts, we call in componentDidMount() the following function in the component:</p>
  
  <pre><code>componentDidMount: function() {
  
      this.Dungeon.Generate();
  
      this.setState({
        board: this.Dungeon.map
      }, function() {
  
        this.generateGamePlay();
  
      });
  
    },
  </code></pre>
  
  <p>this.generateGamePlay() looks like this and basically generates and places the player, boss and items randomly on the board:</p>
  
  <pre><code>generateGamePlay: function() {
  
  var board = this.state.board.slice();
  
  var startPosition = this.randomPosition();
  
  board[startPosition[0]][startPosition[1]] = this.state.player;
  
  var bossPosition = this.randomPosition();
  
  board[bossPosition[0]][bossPosition[1]] = this.state.boss[this.state.dungeonLevel];
  
  this.generateWeapons(this.state.dungeonLevel,board);
  
  this.generateFood(this.state.dungeonLevel, board);
  
  this.generateEnemies(this.state.dungeonLevel, board);
  
  this.setState({
    board: board
  });
  
   },
  </code></pre>
  
  <p>But when a player dies, we call above again to reset the game:</p>
  
  <pre><code>this.Dungeon.Generate();
          //generate a new dungeon map, available in this.Dungeon.map
  
          this.setState({
            board: this.Dungeon.map, currentMessage: "Game restarted", player: player, weapon: weapon, dungeonLevel: 0
            }, function(){
  
                  this.generateGamePlay();
  
            })
  </code></pre>
  
  <p>But then is when my game freezes. So the first time I call this.generateGamePlay() (which calls this.setState) it works but the second time it freezes. Anyone can help me?</p>