examples/opta-mern-stack/client/src/components/create.js
// This function will handle the submission.
This function will handle the submission.
This function will handle the submission .
onSubmit(e) {
    e.preventDefault();
    const newperson = {
      person_name: this.state.person_name,
      person_position: this.state.person_position,
      person_level: this.state.person_level,
    };
    const api_endpoint =Config.API_ENDPOINT;
    axios
      .post(api_endpoint + "/record/add", newperson)
      .then((res) => console.log(res.data));
    this.setState({
      person_name: "",
      person_position: "",
      person_level: "",
    });
  }
onSubmit ( e ) { e . preventDefault ( ) ; const newperson = { person_name : this . state . person_name , person_position : this . state . person_position , person_level : this . state . person_level , } ; const api_endpoint = Config . API_ENDPOINT ; axios . post ( api_endpoint + "/record/add" , newperson ) . then ( ( res ) => console . log ( res . data ) ) ; this . setState ( { person_name : "" , person_position : "" , person_level : "" , } ) ; }
This function will handle the submission.
This function will handle the submission .
// When post request is sent to the create url, axios will add a new record(newperson) to the database. // We will empty the state after posting the data to the database