title: Setting the defultValue of TextField component of Material UI in React
body: <p>I am developing a React JS application. What I am doing now is I am fetching data asynchronously from the server and render the values in the TextField. I know how to do it and my approach is working as well. But, I just do not like my current approach. </p>
  
  <p>This is the working approach</p>
  
  <pre><code>class TestComponent extends React.Component {
  
      constructor(props)
      {
          super(props);
          this.fetchName = this.fetchName.bind(this);
          this.handleChange = this.handleChange.bind(this);
          this.state = {
              name : ''
          }
      }
  
  
      fetchName()
      {
          //get the name asynchronously from the server. I am using Axios
          this.setState({ name : nameValueFromTheServer })
      }
  
  
      handleChange(e)
      {
          this.setState({ name : e.target.value })
      }
  
      render()
      {
          return (
              &lt;MuiThemeProvider&gt;
              &lt;div&gt;
                  &lt;TextField onChange={this.handleChange} label="Name" value={this.state.name} /&gt;
              &lt;/div&gt;
              &lt;/MuiThemeProvider&gt;
          )
      }
  }
  </code></pre>
  
  <p>The thing I do not like about above approach is that I have to implement <code>handleChange</code> method to retrieve the value of the input value. If I do not implement it, I cannot change the name input value because the state value is not changed. To retrieve a simple input value, I have to write extra lines of code. In jQuery, I just retrieve the input value like this, $(selector).val(). Without implementing the <code>handleChange</code> method, I can use the ref like this.</p>
  
  <pre><code>&lt;TextField inputRedf={(input) =&gt; this.tfName = input } label="Name" /&gt;
  </code></pre>
  
  <p>Then I retrieve the value dynamically like this.</p>
  
  <pre><code>this.tfName.value
  </code></pre>
  
  <p>The problem with using the reference is setting the default value which is fetched asynchronously from the server.</p>
  
  <p>I can set the default value like this to the TextField</p>
  
  <pre><code>&lt;TextField inputRedf={(input) =&gt; this.tfName = input } defaultValue={this.state.name} label="Name" /&gt;
  </code></pre>
  
  <p>Pay attention to the defaultValue attribute in the above code. When I set the value using defaultValue, the initial value of the name state will be set to the text field. But we can still change the input value of the name typing in from the UI even if we do not implement the handleChange event. But the problem is that I am getting the data asynchronously and setting the this.state.name dynamically. </p>
  
  <p>So in the component constructor, the name state is empty. Then I set it in the callback of the asynchronous call. But the defaultValue can be set only once. So the input field is always showing empty. What I like to know is, how can I set the defaultValue of the TextField dynamically? The reason I am using ref is that I do not want to implement the onChange event as well to track state the reset the input value. If I could set the defaultValue dynamically, I will just the value dynamically in the callback of the asynchronous call. What is the best solution to simplify this scenario?</p>