-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddExpense.jsx
More file actions
59 lines (47 loc) · 1.2 KB
/
Copy pathAddExpense.jsx
File metadata and controls
59 lines (47 loc) · 1.2 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
53
54
55
56
57
58
59
import { useState } from "react";
function AddExpense({ addExpense }) {
const [title, setTitle] = useState("");
const [amount, setAmount] = useState("");
const [category, setCategory] = useState("Food");
const handleSubmit = (e) => {
e.preventDefault();
addExpense({
id: Date.now(),
title,
amount: Number(amount),
category,
});
setTitle("");
setAmount("");
};
return (
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="Enter title"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>
<br /><br />
<input
type="number"
placeholder="Enter amount"
value={amount}
onChange={(e) => setAmount(e.target.value)}
/>
<br /><br />
<select
value={category}
onChange={(e) => setCategory(e.target.value)}
>
<option>Food</option>
<option>Travel</option>
<option>Bills</option>
<option>Shopping</option>
</select>
<br /><br />
<button type="submit">Add Expense</button>
</form>
);
}
export default AddExpense;