How to Download File in React.js?
To download a file with React.js, we can add the download attribute to an anchor element. For instance, we can write:
We just add the download prop to do the download.
If we don’t want to use an anchor element, we can also use the file-saver package to download our file.
To install it, we run: npm i file-saver
Then we can call the saveAs function from the package by writing:
The first argument is the URL to download and the 2nd argument is the file name of the downloaded file.