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:05,110
So we wanna send our meetup data to a server.
2
00:00:05,110 --> 00:00:07,580
This course is about React.
3
00:00:07,580 --> 00:00:09,130
About the front end.
4
00:00:09,130 --> 00:00:13,260
And therefore here we will not write any server side code
5
00:00:13,260 --> 00:00:15,930
or create our own backend.
6
00:00:15,930 --> 00:00:18,430
I do have separate tutorials on that.
7
00:00:18,430 --> 00:00:20,180
Got my node JS course,
8
00:00:20,180 --> 00:00:23,660
where you learn all about that backend technology,
9
00:00:23,660 --> 00:00:26,710
including how to connect to databases,
10
00:00:26,710 --> 00:00:29,490
how to create REST APIs and much more.
11
00:00:29,490 --> 00:00:31,850
And they got a free tutorial as well
12
00:00:31,850 --> 00:00:35,210
where we also built a REST API in detail
13
00:00:35,210 --> 00:00:37,920
with no CHAZ step-by-step.
14
00:00:37,920 --> 00:00:39,700
Because with the React
15
00:00:39,700 --> 00:00:43,250
or with single page applications in general,
16
00:00:43,250 --> 00:00:46,260
you typically need a backend API
17
00:00:46,260 --> 00:00:48,690
to which you can send your requests.
18
00:00:48,690 --> 00:00:52,140
So a backend, which does not send back HTML
19
00:00:52,140 --> 00:00:55,940
but which instead expects data in a certain format,
20
00:00:55,940 --> 00:00:58,160
typically JSON format,
21
00:00:58,160 --> 00:01:01,940
and which then returns data in that JSON format.
22
00:01:01,940 --> 00:01:04,810
And which simply exposes a couple of URLs
23
00:01:04,810 --> 00:01:06,740
to which you can send requests.
24
00:01:06,740 --> 00:01:10,750
And depending on which URL you're sending a request to,
25
00:01:10,750 --> 00:01:12,560
different things will happen.
26
00:01:12,560 --> 00:01:14,070
That's the kind of backend
27
00:01:14,070 --> 00:01:18,060
you typically connect to with React.
28
00:01:18,060 --> 00:01:21,420
Now you don't connect a front-end application
29
00:01:21,420 --> 00:01:25,120
like React or Angular to a database itself.
30
00:01:25,120 --> 00:01:27,100
I got a full tutorial on that
31
00:01:27,100 --> 00:01:29,850
where I explained why we don't want to do that.
32
00:01:29,850 --> 00:01:32,430
You also find a link to that attached.
33
00:01:32,430 --> 00:01:35,100
You don't connect directly to a database
34
00:01:35,100 --> 00:01:39,370
with React and so on because of security.
35
00:01:39,370 --> 00:01:43,350
All the code you write here in your React application
36
00:01:43,350 --> 00:01:47,000
in the end is exposed to the visitors of your page.
37
00:01:47,000 --> 00:01:49,840
Through to dev tools, If I look at sources,
38
00:01:49,840 --> 00:01:52,020
if I dig into that I can read
39
00:01:52,020 --> 00:01:55,960
the JavaScript code that makes up your application.
40
00:01:55,960 --> 00:01:59,230
It might look a bit different than when we wrote it
41
00:01:59,230 --> 00:02:01,150
but all the code is in there.
42
00:02:01,150 --> 00:02:05,240
And database credentials would be in there as well.
43
00:02:05,240 --> 00:02:07,760
That's why instead we need a backend API,
44
00:02:07,760 --> 00:02:10,780
a backend server to which we can send requests
45
00:02:10,780 --> 00:02:12,630
and then its that server,
46
00:02:12,630 --> 00:02:14,110
which on this server
47
00:02:14,110 --> 00:02:17,810
connects to a database and stores data in a database.
48
00:02:17,810 --> 00:02:20,160
And hence, that's what we're going to do here.
49
00:02:20,160 --> 00:02:21,350
Now, as I mentioned though
50
00:02:21,350 --> 00:02:23,650
we're not going to write our own API.
51
00:02:23,650 --> 00:02:27,660
Instead, we're going to use Firebase as a dummy backend here
52
00:02:27,660 --> 00:02:30,360
Firebase is a service offered by Google.
53
00:02:30,360 --> 00:02:33,510
It is actually made up of a bunch of different services
54
00:02:33,510 --> 00:02:37,070
but it is a service which you can get started with for free.
55
00:02:37,070 --> 00:02:39,780
You just need a Google account.
56
00:02:39,780 --> 00:02:42,920
And it is a service which contains a database
57
00:02:42,920 --> 00:02:46,610
and an API to which we can send requests
58
00:02:46,610 --> 00:02:50,823
which will then ensure that data is saved in that database.
59
00:02:51,790 --> 00:02:54,610
And for this I'll therefore log in here
60
00:02:54,610 --> 00:02:56,043
with my Google account.
61
00:02:56,960 --> 00:03:01,960
And then once logged in, we can create a new project here.
62
00:03:02,040 --> 00:03:04,590
You can enter any project name you want here.
63
00:03:04,590 --> 00:03:08,423
I'll just name it React. Getting dash started.
64
00:03:09,560 --> 00:03:11,050
Click continue.
65
00:03:11,050 --> 00:03:12,940
You can disable Google Analytics.
66
00:03:12,940 --> 00:03:16,250
We don't need that and create that project.
67
00:03:16,250 --> 00:03:17,180
Now, as I said,
68
00:03:17,180 --> 00:03:19,360
Firebase is a service which has a bunch
69
00:03:19,360 --> 00:03:21,170
of built in capabilities.
70
00:03:21,170 --> 00:03:24,100
Here, we'll just use it in a very basic way
71
00:03:24,100 --> 00:03:27,380
to have this dummy backend to talk to.
72
00:03:27,380 --> 00:03:30,110
And I'm using this backend, this service,
73
00:03:30,110 --> 00:03:31,570
because that allows me
74
00:03:31,570 --> 00:03:35,290
to show you how you send requests to a backend.
75
00:03:35,290 --> 00:03:37,220
And you would then do that in the same way
76
00:03:37,220 --> 00:03:39,890
no matter which backend you use in the end.
77
00:03:39,890 --> 00:03:42,690
That's why that's a good service to use.
78
00:03:42,690 --> 00:03:45,320
Now here, we wanna use the real time database
79
00:03:45,320 --> 00:03:48,070
which is one of the features Firebase offers.
80
00:03:48,070 --> 00:03:51,450
And then there click on create database.
81
00:03:51,450 --> 00:03:53,220
Now you can leave to default region
82
00:03:53,220 --> 00:03:55,640
and make sure that you start in test mode
83
00:03:55,640 --> 00:03:57,540
not in locked mode.
84
00:03:57,540 --> 00:04:00,563
Otherwise you'll not be able to send requests.
85
00:04:01,400 --> 00:04:04,840
Now, this sets up a database end, very important,
86
00:04:04,840 --> 00:04:09,200
also immediately an API to which we can send requests.
87
00:04:09,200 --> 00:04:13,340
We can use this URL here to send requests to
88
00:04:13,340 --> 00:04:16,660
and behind the scenes on Firebase servers
89
00:04:16,660 --> 00:04:19,470
those requests will then be parsed.
90
00:04:19,470 --> 00:04:22,820
And depending on which kind of request we send
91
00:04:22,820 --> 00:04:26,480
data attached to the request will be extracted
92
00:04:26,480 --> 00:04:29,880
and stored in the database automatically.
93
00:04:29,880 --> 00:04:31,510
And therefore it can look like
94
00:04:31,510 --> 00:04:34,740
if we're directly sending requests to a database
95
00:04:34,740 --> 00:04:38,610
but we're actually sending requests to that Firebase API
96
00:04:38,610 --> 00:04:42,980
which then behind the scenes stores them in a database.
97
00:04:42,980 --> 00:04:45,060
And therefore that's the URL
98
00:04:45,060 --> 00:04:47,350
to which we now want to send the request
99
00:04:47,350 --> 00:04:49,833
when we submit that form.
100
00:04:51,360 --> 00:04:54,810
Now it's up to us where we wanna send that request.
101
00:04:54,810 --> 00:04:57,280
If that's in the Meetup form component,
102
00:04:57,280 --> 00:05:00,810
or maybe in the we'll Meetup page component.
103
00:05:00,810 --> 00:05:02,990
And since the new Meetup form component
104
00:05:02,990 --> 00:05:06,160
is already quite a big file,
105
00:05:06,160 --> 00:05:09,470
I will actually not add the HTTP code here
106
00:05:09,470 --> 00:05:12,053
but instead in the new Meetup component code.
107
00:05:13,060 --> 00:05:14,880
So in the new Meetup form component,
108
00:05:14,880 --> 00:05:17,630
I just wanna forward that Meetup data
109
00:05:17,630 --> 00:05:19,320
to the parent component.
110
00:05:19,320 --> 00:05:22,130
To the component where we use this component.
111
00:05:22,130 --> 00:05:25,450
And we learned that we can do that with props.
112
00:05:25,450 --> 00:05:29,010
We can accept props here in the new Meetup form.
113
00:05:29,010 --> 00:05:31,800
And then instead of console logging the Meetup data
114
00:05:31,800 --> 00:05:34,430
we can expect that on props,
115
00:05:34,430 --> 00:05:39,430
we have some prop which actually gets function as a value.
116
00:05:39,700 --> 00:05:42,990
A function, which we can then call from inside here.
117
00:05:42,990 --> 00:05:47,400
Let's say the onAddMeetup prop.
118
00:05:47,400 --> 00:05:51,000
The name is up to you because that's our component.
119
00:05:51,000 --> 00:05:54,790
I expect that the value on this prop is a function
120
00:05:54,790 --> 00:05:56,690
so we can execute it here.
121
00:05:56,690 --> 00:06:00,200
And I'll pass Meetup data as a argument.
122
00:06:00,200 --> 00:06:01,840
Now, of course, for this to work
123
00:06:01,840 --> 00:06:05,900
we now need to make sure that in the new Meetup component
124
00:06:05,900 --> 00:06:08,650
we now add this onAddMeetup prop.
125
00:06:10,139 --> 00:06:14,629
And that the value we pass in here is a function.
126
00:06:14,629 --> 00:06:16,810
So here I'll add a new function,
127
00:06:16,810 --> 00:06:20,600
the addMeetupHandler function,
128
00:06:20,600 --> 00:06:24,090
which expects to get some Meetup data
129
00:06:24,090 --> 00:06:26,500
because I'm passing that argument here
130
00:06:26,500 --> 00:06:28,160
when I call the function
131
00:06:28,160 --> 00:06:31,200
from inside the new Meetup form component.
132
00:06:31,200 --> 00:06:33,560
So I expect that data here.
133
00:06:33,560 --> 00:06:37,160
And I then pass this addMeetupHandler function
134
00:06:37,160 --> 00:06:40,740
as a value to onAddMeetup like this.
135
00:06:40,740 --> 00:06:43,763
without parentheses just pointing at it.
136
00:06:45,440 --> 00:06:46,990
Now in this function,
137
00:06:46,990 --> 00:06:49,973
that's where I wanna send a HTTP request.
10777
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.