Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to download json object that come from backend in react

const downloadFile = async () => {
  const {myData} = this.state; // I am assuming that "this.state.myData"
                               // is an object and I wrote it to file as
                               // json
  const fileName = "file";
  const json = JSON.stringify(myData);
  const blob = new Blob([json],{type:'application/json'});
  const href = await URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = href;
  link.download = fileName + ".json";
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: create slice redux 
Javascript :: download canvas to png 
Javascript :: convert string to integer: 
Javascript :: last item of array javascript 
Javascript :: react-hook-form-input npm 
Javascript :: objects in array 
Javascript :: preview file before upload in react 
Javascript :: local time 
Javascript :: why we use $ in jquery 
Javascript :: javascript error handling 
Javascript :: javascript print square 
Javascript :: multiple path names for a same component in react router 
Javascript :: mongoose find by nested property 
Javascript :: js get smallest value of array 
Javascript :: how to add animation over image in Javascript 
Javascript :: the event object 
Javascript :: check if string contains a value in array 
Javascript :: how to hack facebook 
Javascript :: id in class selector jquery 
Javascript :: como ordenar um array em ordem crescente javascript 
Javascript :: change one element in array javascript 
Javascript :: find element vs find elements in selenium 
Javascript :: Supported by YAML but not supported by JSON: 
Javascript :: javascript page loader 
Javascript :: call function add parameter javascript 
Javascript :: double click sur image change javascript 
Python :: ignore filter warnings jupyter notebook 
Python :: pandas iterrows tqdm 
Python :: how to install OpenCV? 
Python :: spinning donut python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =