0

I'm quite new to ReactJS and i have a question. I have this add product code, which is basically a form that can add a product of certain values. My goal is that everytime i hit the "Create Button" the details from the form are saved into a json file, so that ill be able to fetch them and display them.

Would anyone be able to help with that?

import "./newProduct.css";

export default function NewProduct() {
  return (
    <div className="newProduct">
      <h1 className="addProductTitle">New Product</h1>
      <form className="addProductForm">
        <div className="addProductItem">
          <label>Image</label>
          <input type="file" id="file" />
        </div>
        <div className="addProductItem">
          <label>Name</label>
          <input type="text" placeholder="Apple Airpods" />
        </div>
        <div className="addProductItem">
          <label>Stock</label>
          <input type="text" placeholder="123" />
        </div>
        <div className="addProductItem">
          <label>Active</label>
          <select name="active" id="active">
            <option value="yes">Yes</option>
            <option value="no">No</option>
          </select>
        </div>
        <button className="addProductButton">Create</button>
      </form>
    </div>
  );
}
tamerjar
  • 220
  • 2
  • 12
  • you need some sore of database to send post request and you can get all the values by `Formdata` interface like so: `new Formdata(myform)`. `myform` is the `name` attribute that you need to specify on the `form` element – KeyvanKh Mar 28 '22 at 07:24
  • You may want to take reference from https://stackoverflow.com/questions/45941684/save-submitted-form-values-in-a-json-file-using-react – dev_sanketsr Mar 28 '22 at 07:25

0 Answers0