title: How to bind function in constructor that has a parameter in Reactjs
body: <p>So here's my function:</p>
  
  <pre><code>remove(element)
  {   
      this.setState({ search: this.state.search.filter( item =&gt; item !== element ) }); 
  }  
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Warning: setState(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). 
  Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.
  </code></pre>
  
  <p>If I have it set up like this:</p>
  
  <pre><code>constructor()
  {
      this.remove = this.remove.bind(this);
  }
  render() 
  {   
      return (
          &lt;div&gt;
              { this.state.search.map( (item, index) =&gt;  
                  (   
                      &lt;button key={index} onClick={this.remove(item)}&gt;{item.search}: {item.text}&lt;/button&gt;
                  ))  
              }   
              &lt;/div&gt;
          &lt;/div&gt;
      );
  }
  </code></pre>
  
  <p>But if works fine if I remove the binding (well doesn't really matter) from the constructor and change the button line to this:</p>
  
  <pre><code>&lt;button key={index} onClick={this.remove.bind(this, item)}&gt;{item.search}: {item.text}&lt;/button&gt;
  </code></pre>
  
  <p>So my question is, is there a way to bind it in the constructor so that it can take on the parameter?</p>