1function LoginForm() {
2 const [form, setState] = useState({
3 username: '',
4 password: ''
5 });
6
7 const printValues = e => {
8 e.preventDefault();
9 console.log(form.username, form.password);
10 };
11
12 const updateField = e => {
13 setState({
14 ...form,
15 [e.target.name]: e.target.value
16 });
17 };
18
19 return (
20 <form onSubmit={printValues}>
21 <label>
22 Username:
23 <input
24 value={form.username}
25 name="username"
26 onChange={updateField}
27 />
28 </label>
29 <br />
30 <label>
31 Password:
32 <input
33 value={form.password}
34 name="password"
35 type="password"
36 onChange={updateField}
37 />
38 </label>
39 <br />
40 <button>Submit</button>
41 </form>
42 );
43}