Created
September 4, 2016 20:12
-
-
Save flybayer/f2bc381c4772ef5df8b44ca50c0dcd0f to your computer and use it in GitHub Desktop.
Create downloadable text file from JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convertStringToFile = (aString) => { | |
const data = new Blob([aString], {type: 'text/plain'}) | |
return window.URL.createObjectURL(data) | |
} | |
<a | |
download="filename.txt" | |
href={convertStringToFile} | |
> | |
Download | |
</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment