Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,210 --> 00:00:07,390
Now, let me get rid of that dummy title output and let's work on the overall syntax we're using here
2
00:00:08,180 --> 00:00:12,770
thus far, we're storing this array, we're getting back in the input state, and we can absolutely
3
00:00:12,770 --> 00:00:13,250
do that.
4
00:00:13,250 --> 00:00:18,830
But it means that we have to use input state zero if we want to get the values and input, said one.
5
00:00:18,830 --> 00:00:23,330
If we want to get the function to update the values, of course we can do that.
6
00:00:23,330 --> 00:00:26,000
But it's a bit of hard to understand.
7
00:00:26,000 --> 00:00:30,380
Syntax, for example, that this is a function is not immediately obvious.
8
00:00:31,250 --> 00:00:35,470
We can't use a modern JavaScript syntax to make that easier to understand.
9
00:00:35,810 --> 00:00:39,260
We can use a feature called Array de Structuring.
10
00:00:40,110 --> 00:00:41,020
How does it work?
11
00:00:41,450 --> 00:00:45,530
It allows you to pull elements out of an array and store them in separate variables.
12
00:00:45,650 --> 00:00:51,440
So here where you know that you get an array with exactly two elements, you can add square brackets
13
00:00:51,440 --> 00:00:53,840
on the left side of the equals sign.
14
00:00:54,050 --> 00:00:58,960
So by adding them on the left side, you're not using them to create a new array or anything like that.
15
00:00:59,000 --> 00:01:00,880
That would be the case if you use them on the right side.
16
00:01:01,460 --> 00:01:06,170
But instead, this now is a JavaScript syntax that allows you to pull elements out of that array and
17
00:01:06,170 --> 00:01:07,340
store them in variables.
18
00:01:07,940 --> 00:01:14,810
And you add as many variables here, variable names of your choice here between the square brackets
19
00:01:14,810 --> 00:01:17,190
on the left side as you have elements in the array.
20
00:01:17,240 --> 00:01:19,900
So here we have all these exactly two elements.
21
00:01:20,360 --> 00:01:23,310
So we can add two values here with any names you want.
22
00:01:23,660 --> 00:01:25,830
The first element will be our data.
23
00:01:26,180 --> 00:01:31,770
So here that could be input state and the second will be a function to update that data.
24
00:01:31,880 --> 00:01:38,030
Typically you named as set input state or a set, whatever you name your data because you're well,
25
00:01:38,030 --> 00:01:39,370
setting this to a new value.
26
00:01:39,380 --> 00:01:40,580
You are not merging it.
27
00:01:40,580 --> 00:01:42,920
You're not updating it, you're overriding it.
28
00:01:42,920 --> 00:01:44,420
So you're setting some new data.
29
00:01:45,110 --> 00:01:49,820
So now we're using a restructuring and our input state will be our data and that will be the function
30
00:01:49,820 --> 00:01:50,740
to update the data.
31
00:01:51,200 --> 00:01:52,360
That's way easier to use.
32
00:01:52,370 --> 00:02:00,590
Now we can use input state here without the zero to work with our data and we use set input state instead
33
00:02:00,590 --> 00:02:02,920
of input state one to update our data.
34
00:02:03,320 --> 00:02:07,370
And I think that's much easier to read and to understand that it was before.
35
00:02:07,370 --> 00:02:10,610
To be honest, if we save that, it works just as before.
36
00:02:10,850 --> 00:02:13,940
But now we have a syntax that's way easier to understand.
37
00:02:14,260 --> 00:02:18,740
A side note, of course, this button still doesn't do anything because we haven't hooked up any logic,
38
00:02:18,920 --> 00:02:20,460
but we'll do that step by step.
39
00:02:21,170 --> 00:02:26,330
So this is the syntax will actually use the syntax you see in the official docs you'll see for the rest
40
00:02:26,330 --> 00:02:31,700
of this course and the syntax, which is much better to use when working with the use state hook.
4087
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.