title: Download Files from Url using React
body: <p>I have this link <a href="https://carbon-copies-restapi.herokuapp.com/all-order-histories.txt" rel="nofollow noreferrer">https://carbon-copies-restapi.herokuapp.com/all-order-histories.txt</a> which contains some data. I want to download it as a file using React. I tried many solutions from StackOverflow but nothing worked for me.
  One of the solutions I found on the internet that did not work either.</p>
  <pre><code>const downloadFile = async () =&gt; {
  fetch(
    &quot;https://carbon-copies-restapi.herokuapp.com/all-order-histories.txt&quot;
  ).then((response) =&gt; {
    response.blob().then((blob) =&gt; {
      let url = window.URL.createObjectURL(blob);
      let a = document.createElement(&quot;a&quot;);
      a.href = url;
      a.download = &quot;orders.txt&quot;;
      a.click();
    });
    //window.location.href = response.url;
  });
  </code></pre>
  <p>};</p>