title: Functions inside componentDidMount are undefined
body: <p>I have the following block of code:</p>
  <pre><code>class App extends Component {
    constructor(props) {
      super(props);
      this.state = {
        avatar: '',
        ...some more data...
        }
  
        this.fetchUser = this.fetchUser.bind(this);
    }
  
    render() {
      return (
        &lt;div&gt;
          &lt;SearchBox onSubmit={this.fetchUser}/&gt;
          &lt;Card data={this.state} /&gt;
          &lt;BaseMap center={this.state.address}/&gt;
        &lt;/div&gt;
      );
    }
  
    componentDidMount() {
      function fetchUser(username) {
        let url = `https://api.github.com/users/${username}`;
  
        this.fetchApi(url);
      };
  
      function fetchApi(url) {
        fetch(url)
          .then((res) =&gt; res.json())
             .... some data that is being fetched .... 
          });
        };
  
      let url = `https://api.github.com/users/${this.state.username}`;
    }
  }
  
  export default App;
  </code></pre>
  <p>However, I get a <code>TypeError: Cannot read property 'bind' of undefined</code> for the following line: <code>this.fetchUser = this.fetchUser.bind(this);</code> in the <code>constructor</code> where I bind the function to <code>this</code>.</p>
  <p>How can I make the function, which is inside <code>componentDidMount</code> method, visible and available for binding?</p>
  <p>EDIT:</p>
  <p>The reason I'm putting the functions inside <code>componentDidMount</code> was because of a suggestion from another user on StackOverflow. He suggested that:</p>
  <blockquote>
  <p>@BirdMars that because you don't really fetch the data in the parent,
  and the state doesn't really hold the address object. call the fetch in
  componentDidMount of the parent and update the state there. this will
  trigger a second render that will pass in the new state with the
  address object (the first render will be with an empty state.address
  of course until you finish the fetch and update the state)</p>
  </blockquote>