-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIngredientForm.js
More file actions
52 lines (47 loc) · 1.48 KB
/
IngredientForm.js
File metadata and controls
52 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { useState } from "react";
import Card from "../UI/Card";
import "./IngredientForm.css";
import LoadingIndicator from "../UI/LoadingIndicator";
const IngredientForm = React.memo((props) => {
const [enteredTitle, setEnteredTitle] = useState("");
const [enteredAmount, setEnteredAmount] = useState("");
const submitHandler = (event) => {
event.preventDefault();
props.onAddIngredient({ title: enteredTitle, amount: enteredAmount });
};
return (
<section className="ingredient-form">
<Card>
<form onSubmit={submitHandler}>
<div className="form-control">
<label htmlFor="title">Name</label>
<input
type="text"
id="title"
value={enteredTitle}
onChange={(event) => {
setEnteredTitle(event.target.value);
}}
/>
</div>
<div className="form-control">
<label htmlFor="amount">Amount</label>
<input
type="number"
id="amount"
value={enteredAmount}
onChange={(event) => {
setEnteredAmount(event.target.value);
}}
/>
</div>
<div className="ingredient-form__actions">
<button type="submit">Add Ingredient</button>
{props.loading && <LoadingIndicator />}
</div>
</form>
</Card>
</section>
);
});
export default IngredientForm;