Monday, September 14, 2020

Javascript how to save the file to local PC

const handleSaveToPC = jsonData => {

    const fileData = JSON.stringify(jsonData);

    const blob = new Blob([fileData], { type: "text/plain" });

    const url = URL.createObjectURL(blob);

    const link = document.createElement('a');

    link.download = 'filename.json';

    link.href = url;

    link.click();

  }


References: 

https://stackoverflow.com/questions/53449406/write-to-a-text-or-json-file-in-react-with-node

No comments:

Post a Comment