title: Calling Api post method on button click in React
body: <p>I have an event like below:</p>
  
  <pre><code>    handleDownload(e) {
      e.preventDefault();
      alert('Hi');
      let communityName = this.state['selectedCommunity'];
      let files = this.state[files];
  
      fetch(clientConfiguration['filesApi.local'], {
          method: 'POST',
          headers: new Headers(),
          body: JSON.stringify({ communityName: communityName, body: files })
      }).then((res) =&gt; res.json())
          .then((data) =&gt; console.log(data))
          .catch((err) =&gt; console.log(err))
  };
  </code></pre>
  
  <p>I have a button as below:</p>
  
  <pre><code>    renderDownloadButton() {
      if (this.state.files &amp;&amp; this.state.files.filter(i =&gt; i.checked).length) {
          return (
              &lt;button id="download" styles="display: none;" onClick={this.handleDownload} &gt;
                  Download
      &lt;/button&gt;
          );
      }
  };
  </code></pre>
  
  <p>It fires but it is giving following error, any help please - thank you. At</p>
  
  <pre><code>let communityName = this.state['selectedCommunity'];
  </code></pre>
  
  <p>its giving me the error; </p>
  
  <pre><code>Can not read property state undefined
  </code></pre>
  
  <p>Any help please?</p>