“Descargar el archivo JSON React” Código de respuesta

Descargar el archivo JSON React


  const exportData = () => {
    const jsonString = `data:text/json;chatset=utf-8,${encodeURIComponent(
      JSON.stringify(data)
    )}`;
    const link = document.createElement("a");
    link.href = jsonString;
    link.download = "data.json";

    link.click();
  };

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <button type="button" onClick={exportData}>
        Export Data
      </button>
    </div>
  );
}
Daniel Kristoffersen

Donwload datos de React JS en el archivo JSON

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);
}
Perfect Panther

Respuestas similares a “Descargar el archivo JSON React”

Preguntas similares a “Descargar el archivo JSON React”

Más respuestas relacionadas con “Descargar el archivo JSON React” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código