Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,270 --> 00:00:05,183
Now that we know what state is and now
2
00:00:05,183 --> 00:00:09,630
that we also understand how we can listen to events,
3
00:00:09,630 --> 00:00:12,520
we can continue working on this application
4
00:00:12,520 --> 00:00:16,710
and turn this more and more into an expense tracker.
5
00:00:16,710 --> 00:00:19,070
And one important piece is missing.
6
00:00:19,070 --> 00:00:23,550
For example, well, the capability to gather user input
7
00:00:23,550 --> 00:00:26,160
so that users can add their own expenses.
8
00:00:26,160 --> 00:00:29,450
This sounds fairly important for an expense tracker
9
00:00:29,450 --> 00:00:32,020
and up to this point, that's not possible.
10
00:00:32,020 --> 00:00:33,990
So that's what we'll work on next.
11
00:00:33,990 --> 00:00:38,320
And for that, I will, first of all, add new components
12
00:00:38,320 --> 00:00:41,430
and I'll add a new category of components.
13
00:00:41,430 --> 00:00:43,330
You could say, because thus far
14
00:00:43,330 --> 00:00:45,650
the expense components we have here are
15
00:00:45,650 --> 00:00:50,440
about outputting expenses about showing these expenses here.
16
00:00:50,440 --> 00:00:54,180
Now I want to gather user input and therefore
17
00:00:54,180 --> 00:00:57,370
I'll add a new sub folder in the components folder
18
00:00:57,370 --> 00:01:01,710
and I'll simply name it new expense because ultimately
19
00:01:01,710 --> 00:01:04,830
that will be what the components here are about.
20
00:01:04,830 --> 00:01:08,950
About gathering the input for a new expense.
21
00:01:08,950 --> 00:01:11,540
And therefore in here we can add a new expense
22
00:01:11,540 --> 00:01:15,140
started JS file, which will hold the new expense component
23
00:01:15,140 --> 00:01:18,280
in the end and inside of this new expense component
24
00:01:18,280 --> 00:01:21,570
I want to render a form where users can enter
25
00:01:21,570 --> 00:01:23,740
their expense data.
26
00:01:23,740 --> 00:01:27,300
So here I'll add the new expense const
27
00:01:27,300 --> 00:01:30,760
where we have our component function.
28
00:01:30,760 --> 00:01:35,230
And of course I export new expense here to make it available
29
00:01:35,230 --> 00:01:38,330
and we can import react from react.
30
00:01:38,330 --> 00:01:40,820
As I mentioned, you technically don't need to add it.
31
00:01:40,820 --> 00:01:43,800
I covered this in the last course section
32
00:01:43,800 --> 00:01:46,090
but I will still add it here.
33
00:01:46,090 --> 00:01:48,500
Since you will see that in many react projects.
34
00:01:48,500 --> 00:01:51,440
And I want to again, make it clear that JSX
35
00:01:51,440 --> 00:01:54,623
under the hood uses this react library.
36
00:01:55,460 --> 00:01:56,980
Now, as I mentioned, the goal
37
00:01:56,980 --> 00:02:01,980
with this component is to return a form in the end.
38
00:02:02,160 --> 00:02:05,460
A form for our inputs.
39
00:02:05,460 --> 00:02:08,400
And I also want to provide some styling around that form.
40
00:02:08,400 --> 00:02:10,530
So I'll first of all, return a div.
41
00:02:10,530 --> 00:02:13,633
And then inside of that, div return a form.
42
00:02:14,690 --> 00:02:16,100
Now we're speaking of styling,
43
00:02:16,100 --> 00:02:19,380
we can also add a NewExpense.css file
44
00:02:19,380 --> 00:02:22,720
and you find that file attached.
45
00:02:22,720 --> 00:02:25,450
You can either just paste into style to find there
46
00:02:25,450 --> 00:02:30,450
or simply replace your NewExpense.css file with mine.
47
00:02:30,900 --> 00:02:35,250
And then of course, make sure you import NewExpense.css.
48
00:02:35,250 --> 00:02:37,330
And that's all something you learned
49
00:02:37,330 --> 00:02:39,510
about in the last course section.
50
00:02:39,510 --> 00:02:41,720
That's all not directly related
51
00:02:41,720 --> 00:02:45,193
to state or user input, of course, but we'll get there.
52
00:02:46,120 --> 00:02:47,730
So now that we got this imported,
53
00:02:47,730 --> 00:02:51,040
let's add the new expense CSS class to this div
54
00:02:51,040 --> 00:02:53,290
and let's now work on the form.
55
00:02:53,290 --> 00:02:56,030
And actually I'll take that form
56
00:02:56,030 --> 00:02:58,510
and put it into a separate component
57
00:02:58,510 --> 00:03:01,800
just so that the form logic lives in its own component.
58
00:03:01,800 --> 00:03:04,270
And this component is really lean again,
59
00:03:04,270 --> 00:03:05,850
not something you have to do,
60
00:03:05,850 --> 00:03:07,410
but something I will do here.
61
00:03:07,410 --> 00:03:10,140
And I did talk about splitting components
62
00:03:10,140 --> 00:03:12,880
in the last core section as well.
63
00:03:12,880 --> 00:03:16,430
So we can add expense form JS file and in there
64
00:03:16,430 --> 00:03:21,430
create an expense form component function like this.
65
00:03:22,260 --> 00:03:27,150
And then of course also export that function expense form
66
00:03:27,150 --> 00:03:28,270
like this.
67
00:03:28,270 --> 00:03:32,030
And if you want import react from react, even
68
00:03:32,030 --> 00:03:35,210
though it's not technically required, and I'll also set
69
00:03:35,210 --> 00:03:38,570
up some styles, so I'll add a expense form CSS file
70
00:03:38,570 --> 00:03:41,530
and you'll also find that file attached and you
71
00:03:41,530 --> 00:03:43,600
can replace yours with it.
72
00:03:43,600 --> 00:03:46,470
And then just as we saw it, multiple times,
73
00:03:46,470 --> 00:03:48,850
import that CSS file,
74
00:03:48,850 --> 00:03:50,913
the expense form CSS file.
75
00:03:51,830 --> 00:03:54,260
And now here in the expense form component
76
00:03:54,260 --> 00:03:58,960
I will return this form element and in there will then
77
00:03:58,960 --> 00:04:00,763
structure this form.
78
00:04:02,760 --> 00:04:05,810
Now, when it comes to structuring the form
79
00:04:05,810 --> 00:04:09,950
for gathering expense data, I want to let users
80
00:04:09,950 --> 00:04:11,900
enter a title.
81
00:04:11,900 --> 00:04:14,920
I want to let them enter a date or pick a date
82
00:04:14,920 --> 00:04:16,300
with a date picker.
83
00:04:16,300 --> 00:04:20,730
And of course users should be able to enter the amount so
84
00:04:20,730 --> 00:04:24,760
we'll need three input fields and for styling reasons
85
00:04:24,760 --> 00:04:28,680
I'll put every input field in a div where the div has
86
00:04:28,680 --> 00:04:33,680
a class of new dash expense underscore underscore controls.
87
00:04:35,280 --> 00:04:36,790
Or to be precise,
88
00:04:36,790 --> 00:04:40,310
that's actually a div which will hold all inputs
89
00:04:40,310 --> 00:04:43,690
but then I'll create another div in there with a clause
90
00:04:43,690 --> 00:04:48,060
of new dash expense underscore underscore control
91
00:04:48,060 --> 00:04:49,850
for a single input.
92
00:04:49,850 --> 00:04:52,870
And in there, we can now set up a label, for example
93
00:04:52,870 --> 00:04:56,160
title for the first input, and then add an input
94
00:04:56,160 --> 00:05:01,160
of type text like this as a self-closing tag here in react
95
00:05:01,580 --> 00:05:05,430
because these input elements don't have any content
96
00:05:05,430 --> 00:05:07,340
between the opening and closing tags.
97
00:05:07,340 --> 00:05:09,600
So we can and should write it
98
00:05:09,600 --> 00:05:11,593
as a self-closing tag and react.
99
00:05:13,300 --> 00:05:15,680
Now that's how we can create a first input here.
100
00:05:15,680 --> 00:05:19,830
And of course, these are all just default HTML elements
101
00:05:19,830 --> 00:05:22,780
nothing reacts specific here, but we're soon
102
00:05:22,780 --> 00:05:25,750
going to add listeners to wait for user input.
103
00:05:25,750 --> 00:05:29,180
And we're soon going to manage some state with that.
104
00:05:29,180 --> 00:05:31,210
So this is some crucial groundwork
105
00:05:31,210 --> 00:05:33,480
which we have to do first.
106
00:05:33,480 --> 00:05:37,170
Now we can copy this div with the label and title
107
00:05:37,170 --> 00:05:41,200
and duplicate it to also have a input for the amount
108
00:05:41,200 --> 00:05:43,970
the type here could be number.
109
00:05:43,970 --> 00:05:47,220
And we could set a minimum, a minimum value
110
00:05:47,220 --> 00:05:49,930
of zero dot zero one
111
00:05:49,930 --> 00:05:53,470
and set up a step of zero dot zero one as well.
112
00:05:53,470 --> 00:05:56,960
And these are just default HTML attributes
113
00:05:56,960 --> 00:05:58,610
for input elements
114
00:05:58,610 --> 00:06:01,303
which control how this element can be used.
115
00:06:03,150 --> 00:06:06,370
And last but not least I'll replicate the div
116
00:06:06,370 --> 00:06:10,440
One more time to also provide an input for the date
117
00:06:10,440 --> 00:06:12,280
set the type here to date
118
00:06:12,280 --> 00:06:15,680
and this will then automatically give us a date picker.
119
00:06:15,680 --> 00:06:18,100
And I will also set up a min date
120
00:06:18,100 --> 00:06:23,100
and set this to January 1st, 2019 and add a max date
121
00:06:24,120 --> 00:06:29,120
which I'll set to 2022 and there December 31st.
122
00:06:29,370 --> 00:06:31,990
And I'm picking this min and max date
123
00:06:31,990 --> 00:06:35,940
because later we also want to add a filter where
124
00:06:35,940 --> 00:06:40,940
we only provide the years 2019 to 2022 for filtering.
125
00:06:41,500 --> 00:06:42,570
So I want to make sure
126
00:06:42,570 --> 00:06:47,020
that these are also the only years expenses can be set to.
127
00:06:47,020 --> 00:06:49,500
Of course you can play around with these values.
128
00:06:49,500 --> 00:06:52,873
These are just some example values I'm working with here.
129
00:06:54,930 --> 00:06:56,910
Now we got all these inputs.
130
00:06:56,910 --> 00:07:00,810
We now also need a button to submit the form
131
00:07:00,810 --> 00:07:04,000
and therefore right before the form closes
132
00:07:04,000 --> 00:07:05,120
I'll add a new div
133
00:07:05,120 --> 00:07:08,140
next to the other div, which holds the controls.
134
00:07:08,140 --> 00:07:12,660
And in there, I'll add a new expense actions class
135
00:07:12,660 --> 00:07:16,173
like this new dash expense underscore underscore actions.
136
00:07:17,260 --> 00:07:21,250
And then in there add a button where we say add expense
137
00:07:21,250 --> 00:07:22,083
like this,
138
00:07:23,160 --> 00:07:24,750
and I'll set the type
139
00:07:24,750 --> 00:07:28,580
of this button to submit so that when this button is pressed
140
00:07:28,580 --> 00:07:32,783
since it's inside of this form, this form will be submitted.
141
00:07:34,730 --> 00:07:37,550
Now, there was a lot of work on the expense form.
142
00:07:37,550 --> 00:07:41,940
Now we can use the expense form in the new expense component
143
00:07:41,940 --> 00:07:43,210
and therefore we of course want to
144
00:07:43,210 --> 00:07:47,080
import our expense form functional component.
145
00:07:47,080 --> 00:07:50,630
So this component function, we import this
146
00:07:50,630 --> 00:07:55,410
from new expense dot JS without the file extension
147
00:07:55,410 --> 00:07:56,650
like this.
148
00:07:56,650 --> 00:08:00,290
And then here, we can just render this
149
00:08:00,290 --> 00:08:02,430
and add it as an HTML element
150
00:08:02,430 --> 00:08:06,280
in our new expense function body
151
00:08:06,280 --> 00:08:09,900
so that the new expense component will render the
152
00:08:09,900 --> 00:08:11,140
expense form component.
153
00:08:11,140 --> 00:08:13,490
That should be expense form of course, my bad.
154
00:08:13,490 --> 00:08:15,640
So expense form is being rendered here.
155
00:08:15,640 --> 00:08:19,330
And now when I rendered this entire new expense component
156
00:08:19,330 --> 00:08:23,370
in the App JS file, because in there in the end
157
00:08:23,370 --> 00:08:26,393
we're combining all these components.
158
00:08:27,530 --> 00:08:31,990
So here I'll import new expense from dot slash
159
00:08:31,990 --> 00:08:36,520
components slash new expense slash new expense.
160
00:08:36,520 --> 00:08:40,230
That's the path to this new expense JavaScript file.
161
00:08:40,230 --> 00:08:44,450
And then here, finally, instead of this dummy age to tech
162
00:08:44,450 --> 00:08:46,713
we can render new expense like this.
163
00:08:48,120 --> 00:08:49,743
If we now saved this,
164
00:08:50,840 --> 00:08:52,470
this doesn't load
165
00:08:52,470 --> 00:08:54,900
because I have an error in the new expense
166
00:08:54,900 --> 00:08:57,590
JavaScript file. I'm importing expense form
167
00:08:57,590 --> 00:09:00,400
from new expense that's of course not correct.
168
00:09:00,400 --> 00:09:02,680
I should be importing from expense form.
169
00:09:02,680 --> 00:09:04,370
That's where this component lives.
170
00:09:04,370 --> 00:09:06,010
Otherwise I create an infinite loop
171
00:09:06,010 --> 00:09:10,520
and that's this page that's causing this page, not to load.
172
00:09:10,520 --> 00:09:12,590
Now, this works after changing this
173
00:09:12,590 --> 00:09:14,130
and restarting the server
174
00:09:14,130 --> 00:09:16,910
and revisiting local host 3000.
175
00:09:16,910 --> 00:09:21,393
And now we have this form here at the top, which is great.
176
00:09:22,670 --> 00:09:24,650
Now we added the component
177
00:09:24,650 --> 00:09:27,130
but the component is not doing anything.
178
00:09:27,130 --> 00:09:32,130
My next goal is now to make sure that we gather the inputs.
179
00:09:32,700 --> 00:09:35,890
The user chooses here may be on every keystroke
180
00:09:35,890 --> 00:09:38,360
or basically whenever the value in one
181
00:09:38,360 --> 00:09:42,080
of these inputs changes so that we can, for example
182
00:09:42,080 --> 00:09:44,570
locked us to the console for a start.
183
00:09:44,570 --> 00:09:46,670
And that then as a next step
184
00:09:46,670 --> 00:09:49,580
when the form is submitted, we step in
185
00:09:49,580 --> 00:09:53,920
in our code and we take these Gavart input values
186
00:09:53,920 --> 00:09:56,653
and combine them into a new expense object.
15059
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.