title: How can I download an image using React?
body: <p>I'm trying to download files by URL, but the page is redirecting instead of downloading.</p>
  <p>I don't want to use any extensions or libraries.</p>
  <pre><code>    const File = ({href}) =&gt; {
              const onDownload = () =&gt; {
                      const link = document.createElement('a');
                      link.href = href;
                      link.download = 'name';
                      link.click();
                  }
              return (
                  &lt;button onClick={onDownload}&gt;
                      download
                  &lt;/button&gt;
              );
          };
      
      const Downloader = () =&gt; {
          const files = [
              'https://thumbs.dreamstime.com/b/example-red-tag-example-red-square-price-tag-117502755.jpg',
              'https://image.shutterstock.com/image-photo/example-word-written-on-wooden-260nw-1765482248.jpg',
          ]
      
      
          return (&lt;div&gt;{files.map(f =&gt; &lt;File href={f} key={f}/&gt;)} &lt;/div&gt;);
      };
      
      export default Downloader;
  </code></pre>