title: How to disable button in React.js
body: <p>I have this component:</p>
  
  <pre><code>import React from 'react';
  
  export default class AddItem extends React.Component {
  
  add() {
      this.props.onButtonClick(this.input.value);
      this.input.value = '';
  }
  
  
  render() {
      return (
          &lt;div className="add-item"&gt;
              &lt;input type="text" className="add-item__input" ref={(input) =&gt; this.input = input} placeholder={this.props.placeholder} /&gt;
              &lt;button disabled={!this.input.value} className="add-item__button" onClick={this.add.bind(this)}&gt;Add&lt;/button&gt;
          &lt;/div&gt;
      );
  }
  
  }
  </code></pre>
  
  <p>I want the button to be disabled when input value is empty. But the code above doesn't work. It says: </p>
  
  <blockquote>
    <p>add-item.component.js:78 Uncaught TypeError: Cannot read property 'value' of undefined</p>
  </blockquote>
  
  <p>pointing to <code>disabled={!this.input.value}</code>. What can I be doing wrong  here? I'm guessing that perhaps ref isn't created yet when <code>render</code> method is executed. If, so what is the workararound?</p>