Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,060 --> 00:00:05,520
Okay, so enough about JSX and all of that.
2
00:00:05,520 --> 00:00:08,230
Let's now really get our hands dirty.
3
00:00:08,230 --> 00:00:13,230
We have this HTML-ish code here in this App function.
4
00:00:13,860 --> 00:00:17,830
And we have that code here because with React,
5
00:00:17,830 --> 00:00:21,620
we ultimately built our own custom HTML elements
6
00:00:21,620 --> 00:00:22,850
as you learned.
7
00:00:22,850 --> 00:00:25,100
We built those components
8
00:00:25,100 --> 00:00:29,193
and a component is basically just a custom HTML element.
9
00:00:30,060 --> 00:00:33,060
And we do that with this declarative approach,
10
00:00:33,060 --> 00:00:35,180
as I mentioned, which means with React
11
00:00:35,180 --> 00:00:38,100
we defined the desired target state
12
00:00:38,100 --> 00:00:40,180
and React is then responsible
13
00:00:40,180 --> 00:00:44,200
for generating and running the actual DOM instructions
14
00:00:44,200 --> 00:00:46,653
which update what's visible on the screen.
15
00:00:47,870 --> 00:00:49,180
And we can see this here.
16
00:00:49,180 --> 00:00:52,850
This here is our desired target state.
17
00:00:52,850 --> 00:00:57,250
We want to render a div with an h2 tag
18
00:00:57,250 --> 00:01:01,130
with this text inside of it on our screen.
19
00:01:01,130 --> 00:01:04,489
Because in index.js, we rendered as App component,
20
00:01:04,489 --> 00:01:08,090
this custom App HTML element, you could say,
21
00:01:08,090 --> 00:01:10,100
and inside of this custom element,
22
00:01:10,100 --> 00:01:12,000
which turns out just to be a function,
23
00:01:12,000 --> 00:01:14,550
more on that in a second, inside of that,
24
00:01:14,550 --> 00:01:18,060
we in the end just return this HTML code.
25
00:01:18,060 --> 00:01:19,120
So therefore ultimately,
26
00:01:19,120 --> 00:01:23,510
it's this HTML code which is rendered on the screen
27
00:01:23,510 --> 00:01:25,560
and that's indeed what we're seeing here.
28
00:01:26,470 --> 00:01:28,520
Now let's tweak this code a little bit.
29
00:01:28,520 --> 00:01:32,550
And here in App.js, in this function, in this returned
30
00:01:32,550 --> 00:01:35,883
HTML block here, let's add a paragraph,
31
00:01:36,720 --> 00:01:41,440
where we maybe just say, "This is also visible".
32
00:01:41,440 --> 00:01:44,170
If you add this and save this file
33
00:01:44,170 --> 00:01:46,100
and you have this development server running,
34
00:01:46,100 --> 00:01:49,370
which you should, it'll automatically pick up this change,
35
00:01:49,370 --> 00:01:51,940
it'll notice when this file changes,
36
00:01:51,940 --> 00:01:55,160
and it will automatically update what you see on the page.
37
00:01:55,160 --> 00:01:57,820
And therefore, we now also see this text here,
38
00:01:57,820 --> 00:01:59,350
this paragraph.
39
00:01:59,350 --> 00:02:01,200
So that's how we can work with that.
40
00:02:01,200 --> 00:02:02,650
And we can, just to find it,
41
00:02:02,650 --> 00:02:04,580
we wanna have a paragraph here.
42
00:02:04,580 --> 00:02:07,980
Now keep in mind, in regular JavaScript,
43
00:02:07,980 --> 00:02:10,880
you would kind of select the element on the page.
44
00:02:10,880 --> 00:02:14,480
For example, with document.getElementByID('root'),
45
00:02:14,480 --> 00:02:18,180
as we we're doing it here, but then you would not be done.
46
00:02:18,180 --> 00:02:20,410
If you then want to add a paragraph,
47
00:02:20,410 --> 00:02:24,310
you either set the inner HTML content to something,
48
00:02:24,310 --> 00:02:27,600
or you, first of all, create a new element
49
00:02:27,600 --> 00:02:31,100
with document.createElement, creating a paragraph.
50
00:02:31,100 --> 00:02:36,100
And then you got your paragraph here like this.
51
00:02:37,200 --> 00:02:42,200
And you would set the textContent to "This is also visible".
52
00:02:42,660 --> 00:02:45,580
And then you would reach out to some place in the DOM
53
00:02:45,580 --> 00:02:49,600
and then simply call append or appendChild
54
00:02:49,600 --> 00:02:52,540
and add this created paragraph.
55
00:02:52,540 --> 00:02:56,050
That is how you would do it in regular JavaScript.
56
00:02:56,050 --> 00:02:58,650
And this is called imperative.
57
00:02:58,650 --> 00:03:01,750
This is following an imperative approach.
58
00:03:01,750 --> 00:03:04,680
Because you are giving clear instructions,
59
00:03:04,680 --> 00:03:07,220
clear step-by-step instructions,
60
00:03:07,220 --> 00:03:10,273
what JavaScript and the browser should be doing.
61
00:03:11,120 --> 00:03:14,670
Now, this works, but it can get cumbersome,
62
00:03:14,670 --> 00:03:17,750
or complex user interfaces with dozens
63
00:03:17,750 --> 00:03:21,070
or hundreds of elements, which also might be changing
64
00:03:21,070 --> 00:03:23,840
and appearing and disappearing all the time,
65
00:03:23,840 --> 00:03:27,543
having to write all these instructions is very cumbersome.
66
00:03:28,460 --> 00:03:32,450
With React instead, we just define the desired end state,
67
00:03:32,450 --> 00:03:35,550
that we want a div, an h2 tag, and a paragraph,
68
00:03:35,550 --> 00:03:38,530
and React will then generate these instructions
69
00:03:38,530 --> 00:03:42,330
behind the scenes to bring that onto the screen.
70
00:03:42,330 --> 00:03:44,513
That's how this works behind the scenes.
71
00:03:45,450 --> 00:03:48,430
Now I did mention, of course, that for all of that,
72
00:03:48,430 --> 00:03:51,440
React embraces this concept of components.
73
00:03:51,440 --> 00:03:53,260
And as I also already mentioned,
74
00:03:53,260 --> 00:03:56,610
we do have our first component here, App.
75
00:03:56,610 --> 00:04:00,760
So this function in the end as it seems, in App.js,
76
00:04:00,760 --> 00:04:05,300
is a component which is used like a custom HTML element here
77
00:04:05,300 --> 00:04:07,150
in index.js.
78
00:04:07,150 --> 00:04:08,610
Let's now build up on that
79
00:04:08,610 --> 00:04:11,650
and let's build our first custom component.
80
00:04:11,650 --> 00:04:15,350
And since we ultimately want to build that expense tracker,
81
00:04:15,350 --> 00:04:17,899
let's also build our first component
82
00:04:17,899 --> 00:04:20,543
in the context of this expense tracker.
6648
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.