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