I have a string which needs to be downloaded in a txt
file when click on a button. How can this be implemented using React?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
Here's a working example. Enter the text in the input field and click Download txt, this will download a
txt
with the contents you entered in the input.This solution creates a new Blob object of the
text
MIME type and attaches it to thehref
of a temporary anchor (<a>
) element which is then triggered programmatically.This answer was derived from thanhpk's post.