1

Is it possible to write collected data from form to local JSON file with React? If yes can anyone give a good example, if no can you give a good alternative?

Thanks

palaѕн
  • 72,112
  • 17
  • 116
  • 136
Ivana
  • 842
  • 2
  • 15
  • 33
  • Take a look at this [answer](https://stackoverflow.com/questions/49491710/can-reactjs-write-into-file/49491783). – Ajin Kabeer May 24 '20 at 14:50

1 Answers1

0

If you always want to create a new file, one option is to make a downloadable link as shown below. You can even do it programatically

function App() {
  const jsonData = { age: 12, name: "Someone" };
  return (
    <div className="App">
      <a
        href={
          "data:text/json;charset=utf-8," +
          encodeURIComponent(JSON.stringify(jsonData))
        }
        download="fileName.json"
      >
        Download JSON
      </a>
    </div>
  );
}
Jjagwe Dennis
  • 1,643
  • 9
  • 13