title: Save submitted form values in a JSON file using React
body: <p>I'm trying to create a form in react which will update a JSON file with the values in the form upon submit. (The endgame is that this will create an array of data in the JSON file each time the form is submitted which can then be used to populate a "list" of the submitted results elsewhere in the app)</p>
  
  <p>The form itself works OK but every time I press submit I get the error: "TypeError: fs.writeFile is not a function"</p>
  
  <pre><code>import React, { Component } from "react";
  import { Form, Button } from 'semantic-ui-react';
  import jsonfile from'jsonfile';
  
  var file = 'data.json'
  
  var obj = {name: 'JP'}
  
  
  export default class App extends Component {
    constructor(props) {
      super(props)
  
      this.state = {
        name: "",
        email: ""
      }
  
      this.handleChange = this.handleChange.bind(this);
      this.sendDataSomewhere = this.sendDataSomewhere.bind(this);
  }
  
  
  handleChange = (e, {name, value}) =&gt; {
    this.setState({[name]: value})
  }
  
  sendDataSomewhere = function jsonfile(file){
  jsonfile.writeFile(file, obj, function (err) {
    console.error(err);
  });
  };
  
    render() {
      return (
       &lt;div&gt;
        &lt;Form onSubmit={this.sendDataSomewhere}&gt;
          &lt;Form.Field&gt;
            &lt;Form.Input name="name" value={this.state.name} onChange={this.handleChange}/&gt;
          &lt;/Form.Field&gt;
          &lt;Form.Field&gt;
            &lt;Form.Input name="email" value={this.state.email} onChange={this.handleChange}/&gt;
          &lt;/Form.Field&gt;
          &lt;Button type="submit"&gt;Submit&lt;/Button&gt;
         &lt;/Form&gt;
       &lt;/div&gt;
      );
    }
  }
  </code></pre>
  
  <p>If anyone could let me know what I'm doing wrong or provide an example of something similar I would greatly appreciate it.</p>
  
  <p>Thanks</p>