1import React, { Component } from "react";
2
3class Form extends Component {
4 constructor() {
5 super();
6 this.state = {
7 username: "",
8 qty: "",
9 };
10 }
11
12 ChangeHandler = (e) => {
13 this.setState({ [e.target.name]: e.target.value });
14 };
15
16 submitHandler = (e) => {
17 e.preventDefault();
18 console.log(this.state);
19 };
20
21 render() {
22 return (
23 <form onSubmit={this.submitHandler}>
24 <label htmlFor="username"> Name: </label>
25 <input type="text" name="username" id="username" onChange={this.ChangeHandler}/>
26
27 <label htmlFor="qty"> Quantity: </label>
28 <input type="text" name="qty" id="qty" onChange={this.ChangeHandler} />
29
30 <button> Submit </button>
31 </form>
32 );
33 }
34}
35
36export default Form;
37