Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,090 --> 00:00:03,334
This is a very simple demo here.
2
00:00:03,334 --> 00:00:04,260
(whooshing)
3
00:00:04,260 --> 00:00:06,080
I have some content on the page
4
00:00:06,080 --> 00:00:08,680
and when I click delete, I get this overlay,
5
00:00:08,680 --> 00:00:10,920
where I can confirm or cancel.
6
00:00:10,920 --> 00:00:12,960
Now both buttons don't do anything,
7
00:00:12,960 --> 00:00:15,370
but close that overlay,
8
00:00:15,370 --> 00:00:17,800
as does clicking that backdrop.
9
00:00:17,800 --> 00:00:19,820
But what you see on this page here,
10
00:00:19,820 --> 00:00:21,970
or what happens when we click delete,
11
00:00:21,970 --> 00:00:24,953
all of that is controlled with JavaScript.
12
00:00:24,953 --> 00:00:28,620
I got a HTML file, with some very basic
13
00:00:28,620 --> 00:00:32,140
HTML content, some styling, which you can ignore.
14
00:00:32,140 --> 00:00:35,609
And then the magic happens in this app, JS file.
15
00:00:35,609 --> 00:00:39,230
In there, I got some code, that in the end
16
00:00:39,230 --> 00:00:42,000
adds a Listener to this main button,
17
00:00:42,000 --> 00:00:43,780
which we got on the screen.
18
00:00:43,780 --> 00:00:45,850
So too this delete button here.
19
00:00:45,850 --> 00:00:47,270
And when that button is clicked,
20
00:00:47,270 --> 00:00:50,510
I fired this showModalHandler function.
21
00:00:50,510 --> 00:00:53,470
And in there we run a bunch of JavaScript code,
22
00:00:53,470 --> 00:00:57,254
to create various elements, divs, paragraphs
23
00:00:57,254 --> 00:01:00,340
and then the cancel and confirm buttons,
24
00:01:00,340 --> 00:01:02,120
to configure those elements
25
00:01:02,120 --> 00:01:04,950
and add text or CSS classes.
26
00:01:04,950 --> 00:01:07,150
And to add EventListeners to those
27
00:01:07,150 --> 00:01:09,240
elements as well, to then fire
28
00:01:09,240 --> 00:01:11,670
that closeModalHandler function,
29
00:01:11,670 --> 00:01:14,600
which in the end removes the overlay,
30
00:01:14,600 --> 00:01:16,840
this modal as we call it.
31
00:01:16,840 --> 00:01:19,770
And then still in the showModalHandler function,
32
00:01:19,770 --> 00:01:22,240
I got some code that combines all those
33
00:01:22,240 --> 00:01:26,140
created elements and brings them onto the screen.
34
00:01:26,140 --> 00:01:29,040
This is the JavaScript code responsible
35
00:01:29,040 --> 00:01:31,610
for opening this overlay here.
36
00:01:31,610 --> 00:01:35,000
Now it works and it's not too bad,
37
00:01:35,000 --> 00:01:38,470
but it's quite some code for this simple action.
38
00:01:38,470 --> 00:01:41,430
And here we only got one Todo,
39
00:01:41,430 --> 00:01:43,730
in this demo application.
40
00:01:43,730 --> 00:01:46,640
If we would add multiple Todos,
41
00:01:46,640 --> 00:01:50,440
if we would repeat this HTML code multiple times
42
00:01:50,440 --> 00:01:53,100
to render more Todos on the page,
43
00:01:53,100 --> 00:01:56,080
or to even render those Todos dynamically,
44
00:01:56,080 --> 00:01:59,030
after fetching them from a database, for example,
45
00:01:59,030 --> 00:02:02,030
this code would become far more difficult,
46
00:02:02,030 --> 00:02:03,760
far more complex.
47
00:02:03,760 --> 00:02:06,980
And for example, I couldn't just select a button
48
00:02:06,980 --> 00:02:09,310
on the page with that querySelector,
49
00:02:09,310 --> 00:02:11,600
because we would have multiple delete buttons,
50
00:02:11,600 --> 00:02:13,120
for multiple Todos.
51
00:02:13,120 --> 00:02:14,640
And we would have to make sure,
52
00:02:14,640 --> 00:02:16,730
that for different Todos,
53
00:02:16,730 --> 00:02:18,860
different overlays are opened.
54
00:02:18,860 --> 00:02:20,870
And when we confirm the deletion,
55
00:02:20,870 --> 00:02:23,320
the correct Todo is deleted.
56
00:02:23,320 --> 00:02:25,530
We're not even doing that here in this demo,
57
00:02:25,530 --> 00:02:27,730
but that would be more complexity,
58
00:02:27,730 --> 00:02:30,020
which we have to add and handle,
59
00:02:30,020 --> 00:02:33,040
if we build a more realistic app here,
60
00:02:33,040 --> 00:02:35,480
a more realistic website.
61
00:02:35,480 --> 00:02:38,230
And therefore just JavaScript works
62
00:02:38,230 --> 00:02:40,824
and can sometimes be a good choice,
63
00:02:40,824 --> 00:02:43,940
but it can also reach its limits.
64
00:02:43,940 --> 00:02:45,550
And one of the reasons is that
65
00:02:45,550 --> 00:02:49,140
with just the JavaScript, you have to write
66
00:02:49,140 --> 00:02:52,240
every single step that should be taken.
67
00:02:52,240 --> 00:02:54,240
We want to create a element.
68
00:02:54,240 --> 00:02:55,940
We want to set its content.
69
00:02:55,940 --> 00:02:57,520
We want to add classes.
70
00:02:57,520 --> 00:02:59,300
We want to add a click listener.
71
00:02:59,300 --> 00:03:01,490
Then what should happen on that click listener.
72
00:03:01,490 --> 00:03:04,410
Every single step needs to be described.
73
00:03:04,410 --> 00:03:07,710
This way of programming and bringing something
74
00:03:07,710 --> 00:03:11,650
onto the screen, is called an imperative approach.
75
00:03:11,650 --> 00:03:14,340
We simply describe action after action,
76
00:03:14,340 --> 00:03:18,230
step after step and that can reach its limits.
77
00:03:18,230 --> 00:03:21,510
And in addition, even if we don't reach any limits,
78
00:03:21,510 --> 00:03:23,670
we as a developer have to take care
79
00:03:23,670 --> 00:03:26,400
about all the nitty-gritty details.
80
00:03:26,400 --> 00:03:28,570
We have to run the low level code
81
00:03:28,570 --> 00:03:31,670
for creating a button, for setting it's text content.
82
00:03:31,670 --> 00:03:34,840
And therefore in the end, we reinvent the wheel,
83
00:03:34,840 --> 00:03:38,685
over and over again, doing repetitive tasks.
84
00:03:38,685 --> 00:03:42,580
Now here's the same example with React.
85
00:03:42,580 --> 00:03:44,720
This works in exactly the same way,
86
00:03:44,720 --> 00:03:47,350
but the code looks very different.
87
00:03:47,350 --> 00:03:49,220
I got a React project here.
88
00:03:49,220 --> 00:03:52,790
And as a side note, you find both code repositories,
89
00:03:52,790 --> 00:03:55,020
both code snapshots attached.
90
00:03:55,020 --> 00:03:58,370
And here in React.js, this might look
91
00:03:58,370 --> 00:04:01,300
a bit more complex, we got more files involved here,
92
00:04:01,300 --> 00:04:02,850
but that's something we're going to learn
93
00:04:02,850 --> 00:04:05,576
throughout the course, why we have multiple files,
94
00:04:05,576 --> 00:04:10,120
but in the end, this is the main code
95
00:04:10,120 --> 00:04:12,290
that's responsible for bringing this Todo
96
00:04:12,290 --> 00:04:13,440
onto the screen.
97
00:04:13,440 --> 00:04:15,280
And what's very interesting here,
98
00:04:15,280 --> 00:04:18,899
is that we have like a custom HTML component here,
99
00:04:18,899 --> 00:04:21,291
a custom HTML element.
100
00:04:21,291 --> 00:04:25,850
And indeed React is all about those components.
101
00:04:25,850 --> 00:04:29,010
React is all about splitting your application
102
00:04:29,010 --> 00:04:32,550
into small building blocks, small components,
103
00:04:32,550 --> 00:04:34,820
where every building block, every component,
104
00:04:34,820 --> 00:04:37,830
has a clear task and therefore your code
105
00:04:37,830 --> 00:04:40,050
stays maintainable and manageable
106
00:04:40,050 --> 00:04:44,000
and React, the library, will do the heavy lifting
107
00:04:44,000 --> 00:04:46,610
of rendering something on the screen
108
00:04:46,610 --> 00:04:49,470
and of combining all your code.
109
00:04:49,470 --> 00:04:51,360
So for example, if we look into the code
110
00:04:51,360 --> 00:04:53,690
for this custom element, which we built here,
111
00:04:53,690 --> 00:04:55,980
which lives in this Todo.js file,
112
00:04:55,980 --> 00:04:59,140
then we here again see that I have some HTML code
113
00:04:59,140 --> 00:05:01,580
for rendering a Todo, but that we have
114
00:05:01,580 --> 00:05:03,770
some kind of placeholder in here
115
00:05:03,770 --> 00:05:05,750
and then some kind of other code,
116
00:05:05,750 --> 00:05:07,810
which we don't fully understand yet,
117
00:05:07,810 --> 00:05:09,300
but which we will understand
118
00:05:09,300 --> 00:05:11,720
and learn about throughout this course.
119
00:05:11,720 --> 00:05:13,080
And in the end, that's the code
120
00:05:13,080 --> 00:05:15,550
responsible for rendering such a Todo
121
00:05:15,550 --> 00:05:19,100
and for rendering the modal, this overlay here,
122
00:05:19,100 --> 00:05:22,290
as well and for rendering it conditionally.
123
00:05:22,290 --> 00:05:25,350
And what's interesting here, is that even though
124
00:05:25,350 --> 00:05:28,360
we don't understand this code yet
125
00:05:28,360 --> 00:05:30,460
and even though it's certainly strange
126
00:05:30,460 --> 00:05:34,530
that we have HTML code in JavaScript files,
127
00:05:34,530 --> 00:05:36,266
even though that's all weird,
128
00:05:36,266 --> 00:05:39,940
we can definitely see that we don't have a bunch
129
00:05:39,940 --> 00:05:42,750
of step-by-step instructions here.
130
00:05:42,750 --> 00:05:45,640
Instead, we kind of define what we want to have
131
00:05:45,640 --> 00:05:47,330
as an end result.
132
00:05:47,330 --> 00:05:49,700
And then we have some placeholders,
133
00:05:49,700 --> 00:05:51,790
some flexible elements there.
134
00:05:51,790 --> 00:05:54,790
And then we have very simple instructions here,
135
00:05:54,790 --> 00:05:57,060
which in the end then will be processed
136
00:05:57,060 --> 00:06:01,200
by React to change what's visible on the screen.
137
00:06:01,200 --> 00:06:04,250
And all these low level instructions
138
00:06:04,250 --> 00:06:07,345
for creating elements and setting text continents on,
139
00:06:07,345 --> 00:06:10,330
those instructions are not written by us
140
00:06:10,330 --> 00:06:12,910
when using React, instead they will be written,
141
00:06:12,910 --> 00:06:15,980
or defined if you wanna call it like this,
142
00:06:15,980 --> 00:06:17,790
by the React library.
143
00:06:17,790 --> 00:06:21,690
We, as a React developer, work on a higher level,
144
00:06:21,690 --> 00:06:24,390
which makes working with React and which makes
145
00:06:24,390 --> 00:06:28,319
building complex user interfaces way easier.
146
00:06:28,319 --> 00:06:31,810
And that is why we want to use React.js,
147
00:06:31,810 --> 00:06:34,021
it makes building modern, rich, complex
148
00:06:34,021 --> 00:06:36,950
user interfaces easier.
149
00:06:36,950 --> 00:06:39,530
And it does so, by giving us
150
00:06:39,530 --> 00:06:44,180
a higher level syntax, where we write code
151
00:06:44,180 --> 00:06:46,445
in a declarative way, in a declarative
152
00:06:46,445 --> 00:06:49,774
component-focused way, we define
153
00:06:49,774 --> 00:06:51,870
what we wanna have on the screen.
154
00:06:51,870 --> 00:06:53,800
What the end goal is.
155
00:06:53,800 --> 00:06:57,020
We create these custom HTML elements
156
00:06:57,020 --> 00:06:59,400
and React will do the rest.
157
00:06:59,400 --> 00:07:01,320
And one side effect, for example,
158
00:07:01,320 --> 00:07:03,270
is that if we wanted more than one Todo,
159
00:07:03,270 --> 00:07:06,473
we could just copy that custom element,
160
00:07:07,980 --> 00:07:10,680
change maybe that text, that configuration
161
00:07:11,660 --> 00:07:14,310
and boom, we got a second Todo here.
162
00:07:14,310 --> 00:07:16,220
And we got up button on that Todo,
163
00:07:16,220 --> 00:07:18,146
which works as well.
164
00:07:18,146 --> 00:07:21,200
And that is why we use technologies
165
00:07:21,200 --> 00:07:23,523
or frameworks like React.
12567
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.