title: React onClick fires multiple times on load and doesn't contain callback function in component props
body: <p>I believe I have two basic problems, which are probably connected. I'm trying to place an event handler with a callback function on a nested component. It didn't seem to be doing anything, so I replaced the callback function with an alert of <code>JSON.stringify(this.props)</code> to see if that would shed any light. It illuminated two problems: 1) my callback function was not in the props. 2) the alert popped up 2 times on page load, but did not pop up on click, like it was supposed to. I'm working through <a href="https://reactforbeginners.com/" rel="nofollow">this React tutorial</a>. Here are the relevant components:</p>
  
  <pre><code>var App = React.createClass({
    mixins: [Catalyst.LinkedStateMixin],
    getInitialState: function(){
      return {
        fishes: {},
        order: {}
      }
    },
    componentDidMount: function(){
      base.syncState(this.props.params.storeId + '/fishes', {
        context: this,
        state: 'fishes'
      });
      var localStorageRef = localStorage.getItem('order-' + this.props.params.storeId);
      if(localStorageRef){
        this.setState({
          order: JSON.parse(localStorageRef)
        });
      }
    },
    componentWillUpdate: function(nextProps, nextState){
      localStorage.setItem('order-' + this.props.params.storeId, JSON.stringify(nextState.order));
    },
    loadSamples: function(){
      this.setState({
        fishes: require('./sample-fishes.js')
      });
    },
    addFish: function(fish){
      var timestamp = (new Date()).getTime();
      this.state.fishes['fish-' + timestamp] = fish;
      this.setState({ fishes: this.state.fishes });
    },
    removeFish: function(key){
      if(confirm("Are you sure you want to remove this fish?")){
        this.state.fishes[key] = null;
        this.setState({ fishes: this.state.fishes });
      }
    },
    addToOrder: function(key){
      this.state.order[key] = this.state.order[key] + 1 || 1;
      this.setState({ order: this.state.order });
    },
  // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; the function I'm having trouble with &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
    removeFromOrder: function(key){  
      alert('hi');
      delete this.state.order[key];
      this.setState({ order: this.state.order });
    },
    renderFish(key){
      return &lt;Fish key={key} index={key} details={this.state.fishes[key]} addToOrder={this.addToOrder}/&gt;
    },
    render: function(){
      return (
        &lt;div className="catch-of-the-day"&gt;
          &lt;div className="menu"&gt;
            &lt;Header tagline="Fresh Seafood Market"/&gt;
            &lt;ul className="list-of-fish"&gt;
              {/*{ Object.keys(this.state.fishes).map(this.renderFish) }*/}
              { Object.keys(this.state.fishes).length &gt; 0 ? Object.keys(this.state.fishes).map(this.renderFish) : &lt;li&gt;No Fishes!&lt;/li&gt; }
            &lt;/ul&gt;
          &lt;/div&gt;
  // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; I pass the function through to the Order component &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
          &lt;Order fishes={this.state.fishes} order={this.state.order} removeFromOrder={this.removeFromOrder}/&gt;
          &lt;Inventory fishes={this.state.fishes} addFish={this.addFish} removeFish={this.removeFish} loadSamples={this.loadSamples} linkState={this.linkState}/&gt;
        &lt;/div&gt;
      )
    }
  });
  
  var Order = React.createClass({
    renderOrder: function(key){
      var fish = this.props.fishes[key];
      var count = this.props.order[key];
  // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; the onClick I'm having trouble with &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
      var removeButton = &lt;button onCLick={this.props.removeFromOrder.bind(null, key)}&gt;&amp;times;&lt;/button&gt;
      // var removeButton = &lt;button onCLick={alert(JSON.stringify(this.props))}&gt;&amp;times;&lt;/button&gt;
      if(!fish) {
        return &lt;li key={key}&gt;Sorry, that fish is no longer available! {removeButton}&lt;/li&gt;
        // return &lt;li key={key}&gt;Sorry, that fish is no longer available!&lt;/li&gt;
      }
      return (
        &lt;li key={key}&gt;
          {count}lbs
          {" " + fish.name}
          &lt;span className="price"&gt;{helpers.formatPrice(count * fish.price)} {removeButton}&lt;/span&gt;
          {/*&lt;span className="price"&gt;{helpers.formatPrice(count * fish.price)}&lt;/span&gt;*/}
        &lt;/li&gt;
      )
    },
    render: function(){
      var orderIds = Object.keys(this.props.order);
      var total = orderIds.reduce((prevTotal, key)=&gt;{
        var fish = this.props.fishes[key];
        var count = this.props.order[key];
        var isAvailable = fish &amp;&amp; fish.status === 'available';
        if(isAvailable) {
          return prevTotal + (count * parseInt(fish.price) || 0);
        }
        return prevTotal;
      }, 0);
      return (
        &lt;div className="order-wrap"&gt;
          &lt;h2 className="order-title"&gt;Your Order&lt;/h2&gt;
          &lt;ul className="order"&gt;
            { orderIds.length &gt; 0 ? orderIds.map(this.renderOrder) : ""}
            &lt;li className="total"&gt;
              &lt;strong&gt;Total:&lt;/strong&gt;
              {helpers.formatPrice(total)}
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
      )
    }
  });
  </code></pre>
  
  <p>The props for Order should include: the available fishes with all of their details, the current order with a fish id and quantity, and the removeFromOrder callback. When I explore the component in React dev tools, it has all of these things. </p>
  
  <p>When I replace the removeFromOrder callback with an alert of the props, what happens is: 
  - on click, nothing
  - on page refresh, two alerts pop up: the props in the first include the current order and an empty fishes array, the props in the second include the current order and the populated fishes array. Neither show the removeFromOrder callback function, which appears to be undefined from the perspective of the event listener. </p>
  
  <p>On a potentially related note, when I explore the component in React dev tools and hover over a list item in the Order, I get the following error: <code>TypeError: node.getBoundingClientRect is not a function</code>. I'm not sure if this is part of my problem; if it's not, I'm not too concerned about it, since it only seems to pop up when I hover over the element in dev tools. </p>
  
  <p>Thank you for reading this long thing, and any help would be much appreciated!</p>