title: React js Maximum update depth exceeded
body: <p>i'm doing a condition for a update in my code. Basically,
  my code is working with this line</p>
  <pre><code>{this.state.index === 20 ? this.setState({index: 0,index2: 1}) : null }
  </code></pre>
  <p>(this line is in the render)</p>
  <p>And now i want to do a comparaison with a variable.
  but when i'm doing</p>
  <pre><code>{this.state.index === this.state.list.length ? this.setState({index: 0,index2: 1}) : null }
  </code></pre>
  <p>i have the error</p>
  <pre><code>Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
  </code></pre>
  <p>I don’t understand the difference between the two lines, so I can’t understand why I have this mistake. Can someone explain to me why I have this? thx</p>
  <p>UPDATE: my render :</p>
  <pre><code> render() {
      return (
        &lt;div&gt;
            Search Film :
        &lt;form onSubmit={this.mySubmitHandler}&gt;
        &lt;input
          type='text'
          onChange={this.myChangeHandler}
        /&gt;
        &lt;input
          type='submit'
        /&gt;
        &lt;/form&gt;
           {this.state.list.slice(this.state.index, this.state.index2).map(function(stock, id){
           return (&lt;p key={id}&gt; Title : {stock.title}  &lt;br&gt;&lt;/br&gt;release date : {stock.release_date}&lt;br&gt;&lt;/br&gt; popularité : {stock.popularity} &lt;br&gt;&lt;/br&gt; résumé : {stock.overview.substring(0,150)}...&lt;/p&gt;)})}
  
           {this.state.index === this.state.list.length ? this.setState({index: 0,index2: 1}) : null }
       {this.state.index === -1 ? this.setState({index: 0,index2: 1}) : null }
  
  
          Top {this.state.list.length} Search : {this.state.index + 1}/ {this.state.list.length}
          &lt;button onClick={() =&gt; {this.setState({index: this.state.index + 1,index2: this.state.index2 + 1})}}&gt;Next Film&lt;/button&gt;
      &lt;button onClick={() =&gt; {this.setState({index: this.state.index - 1,index2: this.state.index2 - 1})}}&gt;Previous Film&lt;/button&gt;
      &lt;/div&gt;
  
      );
    }
  </code></pre>