Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,070 --> 00:00:04,800
Now, if you take a look at a React project
2
00:00:04,800 --> 00:00:07,680
like this React demo I showed you
3
00:00:07,680 --> 00:00:09,690
in the first course section
4
00:00:09,690 --> 00:00:13,260
to which you again, find a link attached to this lecture,
5
00:00:13,260 --> 00:00:15,540
if you take a look at such a project,
6
00:00:15,540 --> 00:00:20,540
you'll note that in the annex html file that you find there,
7
00:00:20,820 --> 00:00:24,240
you won't find any script tag.
8
00:00:24,240 --> 00:00:28,800
There in this index html file in the head section,
9
00:00:28,800 --> 00:00:32,430
I have some meta tags and I have link tags,
10
00:00:32,430 --> 00:00:35,040
but I have no script tag there.
11
00:00:35,040 --> 00:00:38,010
And in the body, I just have the no script tag
12
00:00:38,010 --> 00:00:39,600
that shows a fallback message
13
00:00:39,600 --> 00:00:43,260
if the user has disabled JavaScript in their browser,
14
00:00:43,260 --> 00:00:46,530
but I got no script tag in there.
15
00:00:46,530 --> 00:00:48,930
Absolutely no script text
16
00:00:48,930 --> 00:00:52,650
and we also never add script text to that file.
17
00:00:52,650 --> 00:00:54,780
Nonetheless, as you can of course tell
18
00:00:54,780 --> 00:00:57,900
if I reload this here, this app works
19
00:00:57,900 --> 00:01:00,810
and JavaScript code clearly is executing
20
00:01:00,810 --> 00:01:03,570
because the React app is executing.
21
00:01:03,570 --> 00:01:06,570
And React of course, in the end, is JavaScript code.
22
00:01:06,570 --> 00:01:10,560
A special JavaScript code, but it is JavaScript code.
23
00:01:10,560 --> 00:01:12,300
So why is this working?
24
00:01:12,300 --> 00:01:15,660
Well, because as mentioned at the end of the last lecture,
25
00:01:15,660 --> 00:01:20,400
React projects use a build process, which simply means,
26
00:01:20,400 --> 00:01:25,080
the code you write is not the code that gets executed
27
00:01:25,080 --> 00:01:28,230
like this, at least, in the browser.
28
00:01:28,230 --> 00:01:32,970
Instead, the code you write is transformed behind the scenes
29
00:01:32,970 --> 00:01:36,000
before it's handed off to the browser.
30
00:01:36,000 --> 00:01:39,240
In this demo project on CodeSandbox,
31
00:01:39,240 --> 00:01:41,220
but also in the local projects
32
00:01:41,220 --> 00:01:43,530
I'll use throughout this course,
33
00:01:43,530 --> 00:01:45,810
this is done with help of a tool
34
00:01:45,810 --> 00:01:47,940
that's running in the background.
35
00:01:47,940 --> 00:01:49,980
And you can actually see that tool
36
00:01:49,980 --> 00:01:52,170
in the package.json file.
37
00:01:52,170 --> 00:01:56,190
This file simply lists all the dependencies of this project,
38
00:01:56,190 --> 00:01:58,770
all the libraries used by that project,
39
00:01:58,770 --> 00:02:00,540
and therefore, of course, for example,
40
00:02:00,540 --> 00:02:04,890
in there we find the React libraries, the two packages
41
00:02:04,890 --> 00:02:08,070
that make up the React library to be precise.
42
00:02:08,070 --> 00:02:09,810
But here in this example,
43
00:02:09,810 --> 00:02:14,400
we also find the React Scripts library in addition.
44
00:02:14,400 --> 00:02:16,470
And this is actually a library
45
00:02:16,470 --> 00:02:19,380
that's not going to be executed in the browser
46
00:02:19,380 --> 00:02:23,100
or that's used by React once it's running in the browser,
47
00:02:23,100 --> 00:02:27,060
but instead this React Scripts package here
48
00:02:27,060 --> 00:02:30,720
provides a bunch of tools that take your code
49
00:02:30,720 --> 00:02:33,810
and transform it behind the scenes
50
00:02:33,810 --> 00:02:36,750
before it's then injected into the browser.
51
00:02:36,750 --> 00:02:40,050
Or to be precise, before it's then injected
52
00:02:40,050 --> 00:02:44,130
with help of a script tag into the HTML file here.
53
00:02:44,130 --> 00:02:46,590
If you take a look at this running website,
54
00:02:46,590 --> 00:02:49,290
for example, by opening it in a new window,
55
00:02:49,290 --> 00:02:52,890
and you then there inspect this page
56
00:02:52,890 --> 00:02:55,500
so that the browser developer tools open up,
57
00:02:55,500 --> 00:02:59,850
you'll see that now there are some script tags in there.
58
00:02:59,850 --> 00:03:02,520
Actually multiple script tags.
59
00:03:02,520 --> 00:03:06,660
And these script elements were generated and injected
60
00:03:06,660 --> 00:03:10,200
into this HTML file automatically behind the scenes
61
00:03:10,200 --> 00:03:14,730
by this built process that's running in the background.
62
00:03:14,730 --> 00:03:18,030
This preview website, which we see here,
63
00:03:18,030 --> 00:03:20,520
is being served by a development server
64
00:03:20,520 --> 00:03:24,240
that's also running in the background on CodeSandbox.
65
00:03:24,240 --> 00:03:26,400
In a local project on the upper hand,
66
00:03:26,400 --> 00:03:30,120
you had to explicitly start that development server.
67
00:03:30,120 --> 00:03:31,920
And it's this development server
68
00:03:31,920 --> 00:03:35,220
which is watching your source code behind the scenes,
69
00:03:35,220 --> 00:03:38,280
and which is then also kind of transforming that source code
70
00:03:38,280 --> 00:03:42,510
behind the scenes and which is then adjusting the HTML file
71
00:03:42,510 --> 00:03:44,730
to contain these script elements
72
00:03:44,730 --> 00:03:48,600
that do then load that transformed source code.
73
00:03:48,600 --> 00:03:53,100
So that the transformed source code is executed on the page.
74
00:03:53,100 --> 00:03:55,500
And why do we use such a built process?
75
00:03:55,500 --> 00:03:58,770
Why does the code need to be transformed?
76
00:03:58,770 --> 00:04:01,350
Well, for two main reasons.
77
00:04:01,350 --> 00:04:06,090
The first reason is that raw unprocessed React code
78
00:04:06,090 --> 00:04:08,730
won't execute in the browser.
79
00:04:08,730 --> 00:04:13,730
Mostly because React code uses this special JSX feature.
80
00:04:15,000 --> 00:04:17,670
Now, you will learn more about writing React code
81
00:04:17,670 --> 00:04:22,530
and about JSX later once we start diving into React.
82
00:04:22,530 --> 00:04:26,520
JSX code simply is this HTML code
83
00:04:26,520 --> 00:04:28,950
written in JavaScript files.
84
00:04:28,950 --> 00:04:31,410
Out of the box, this would not work
85
00:04:31,410 --> 00:04:34,800
because this is not a standard JavaScript feature.
86
00:04:34,800 --> 00:04:37,800
If you would try to use this kind of code
87
00:04:37,800 --> 00:04:40,950
in our default JavaScript project here,
88
00:04:40,950 --> 00:04:42,990
for example in the AppJS file,
89
00:04:42,990 --> 00:04:47,070
if you would try to add like a a div in there,
90
00:04:47,070 --> 00:04:49,870
and you would open this website preview
91
00:04:50,970 --> 00:04:53,220
and try to reload this page,
92
00:04:53,220 --> 00:04:56,670
you would see that you would get an error.
93
00:04:56,670 --> 00:05:00,030
An error that in the end points at this div here.
94
00:05:00,030 --> 00:05:03,300
Because this indeed is not a standard JavaScript feature,
95
00:05:03,300 --> 00:05:05,463
it does not work out of the box.
96
00:05:06,690 --> 00:05:09,810
So for that reason, to enable this syntax
97
00:05:09,810 --> 00:05:13,590
which is crucial in React apps as you will learn,
98
00:05:13,590 --> 00:05:16,320
because React will be all about including
99
00:05:16,320 --> 00:05:20,580
this HTML-like code in your JavaScript files,
100
00:05:20,580 --> 00:05:23,910
to enable this feature, the code must be transformed
101
00:05:23,910 --> 00:05:26,790
so that you can use it whilst writing the code
102
00:05:26,790 --> 00:05:30,090
but it's transformed to something JavaScript knows
103
00:05:30,090 --> 00:05:33,090
before the code gets executed in the browser.
104
00:05:33,090 --> 00:05:36,240
That's one reason for using a build process.
105
00:05:36,240 --> 00:05:39,030
Another reason is that the code you write
106
00:05:39,030 --> 00:05:41,400
would not be optimized for production,
107
00:05:41,400 --> 00:05:44,550
it would not be minified, for example.
108
00:05:44,550 --> 00:05:47,340
Minification simply means that, for example,
109
00:05:47,340 --> 00:05:51,510
names of variables or functions are shortened
110
00:05:51,510 --> 00:05:54,330
to reduce the amount of JavaScript code
111
00:05:54,330 --> 00:05:56,250
that's served to the user.
112
00:05:56,250 --> 00:05:57,960
If you take a look at the code
113
00:05:57,960 --> 00:06:00,240
that is served to the user here
114
00:06:00,240 --> 00:06:04,170
by, for example, visiting one of these imported code files
115
00:06:04,170 --> 00:06:06,690
that is served here in CodeSandbox,
116
00:06:06,690 --> 00:06:09,510
you'll see that it looks something like this.
117
00:06:09,510 --> 00:06:10,800
Pretty unreadable,
118
00:06:10,800 --> 00:06:12,960
not the kind of code we would like to work on
119
00:06:12,960 --> 00:06:17,040
as a developer, but valid JavaScript code in the end.
120
00:06:17,040 --> 00:06:20,250
Though it is code that's highly optimized
121
00:06:20,250 --> 00:06:24,060
to be as short and small as possible
122
00:06:24,060 --> 00:06:25,950
to reduce the amount of code
123
00:06:25,950 --> 00:06:29,310
that has to be downloaded by the website visitor.
124
00:06:29,310 --> 00:06:31,860
So that's another reason why React projects
125
00:06:31,860 --> 00:06:34,680
typically require a built process.
126
00:06:34,680 --> 00:06:37,890
And the good news are that if you create a React project
127
00:06:37,890 --> 00:06:39,510
on CodeSandbox
128
00:06:39,510 --> 00:06:44,070
or with help of tools like Create React app or Vite,
129
00:06:44,070 --> 00:06:45,840
so if you're using projects
130
00:06:45,840 --> 00:06:47,790
as we're using them in this course,
131
00:06:47,790 --> 00:06:51,810
those projects all come with such a built process.
132
00:06:51,810 --> 00:06:55,200
So you don't have to go through any custom setup
133
00:06:55,200 --> 00:06:57,540
or tweak anything on your own.
134
00:06:57,540 --> 00:07:00,150
But that's also the reason why you also need
135
00:07:00,150 --> 00:07:02,370
to install NodeJS on your system
136
00:07:02,370 --> 00:07:05,190
in order to work on React projects.
137
00:07:05,190 --> 00:07:09,330
Because NodeJS is not just used to install packages
138
00:07:09,330 --> 00:07:12,750
with the NPM command or to create projects
139
00:07:12,750 --> 00:07:16,170
with the NPX command as you already learned it,
140
00:07:16,170 --> 00:07:18,690
but instead it's also used behind the scenes
141
00:07:18,690 --> 00:07:22,170
by these tools that are used by that build process
142
00:07:22,170 --> 00:07:24,330
that's running behind the scenes.
143
00:07:24,330 --> 00:07:27,990
So NodeJS is also needed and used behind the scenes
144
00:07:27,990 --> 00:07:32,040
to make sure that your React code gets transformed.
145
00:07:32,040 --> 00:07:34,080
So that of course, was a lot of talking
146
00:07:34,080 --> 00:07:37,320
about the build process, but it is important to understand
147
00:07:37,320 --> 00:07:40,230
that such a build process is used behind the scenes
148
00:07:40,230 --> 00:07:42,060
and why it's being used.
149
00:07:42,060 --> 00:07:44,700
Back in our vanilla JavaScript project here
150
00:07:44,700 --> 00:07:46,530
which we'll use for this refresher,
151
00:07:46,530 --> 00:07:49,740
we should therefore get rid of this invalid JavaScript code
152
00:07:49,740 --> 00:07:52,290
because this project here indeed does not come
153
00:07:52,290 --> 00:07:55,650
with a build process that would convert this JSX code
154
00:07:55,650 --> 00:07:57,330
to valid JavaScript code,
155
00:07:57,330 --> 00:07:59,910
and therefore here we can't use JSX code.
156
00:07:59,910 --> 00:08:02,823
But we also don't need it for this refresher.
12687
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.