Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,450 --> 00:00:08,070
Now that we have our search component, we might actually want to be able to use this component multiple
2
00:00:08,070 --> 00:00:16,170
times because if we look at the code for our input, all it is, is just an input that doesn't need
3
00:00:16,170 --> 00:00:21,230
any local state, even though it seems like we're calling set state in our input.
4
00:00:21,780 --> 00:00:29,790
It's really just a function that we're passing from the context of our app component into the on change
5
00:00:29,790 --> 00:00:31,550
handler of our input.
6
00:00:32,310 --> 00:00:37,890
But this means that we can probably move this into its own component because maybe we want to have a
7
00:00:37,890 --> 00:00:39,540
reusable search component.
8
00:00:40,470 --> 00:00:41,740
Well, how would we do this?
9
00:00:42,570 --> 00:00:45,180
Well, let's just make a new component.
10
00:00:46,670 --> 00:00:48,020
Called search box.
11
00:00:50,510 --> 00:00:59,210
And we'll create the usual file search box dot component Dutch ASX now, some of you might have noticed
12
00:00:59,210 --> 00:01:03,740
why is it that some of our files have Duchesse in some have J.S..
13
00:01:04,650 --> 00:01:11,400
Well, you remember how I mentioned earlier that create, react and hides away some of the configuration
14
00:01:11,400 --> 00:01:13,170
for Web pack and babble?
15
00:01:14,010 --> 00:01:22,080
Well, what babble does is it helps transpire down any of the modern JavaScript, including James style
16
00:01:22,140 --> 00:01:30,810
files that we write into older versions of JavaScript in the public folder when we finally run our build
17
00:01:30,810 --> 00:01:33,930
script inside of our scripts file.
18
00:01:35,790 --> 00:01:37,740
Now in this transform.
19
00:01:38,660 --> 00:01:45,110
If we look at our docs file for Afghans, we actually see that it says JavaScript babble down here.
20
00:01:45,650 --> 00:01:52,010
So even though we're writing Jass code here, right, because we're rendering HTML in our JavaScript
21
00:01:52,610 --> 00:02:00,530
babble knows that it should probably run this regardless through a transform, even though it's not
22
00:02:00,530 --> 00:02:02,120
a sex file type.
23
00:02:02,960 --> 00:02:09,350
We'll explore this much later in the course when we actually write our own Web page embattle configurations.
24
00:02:09,650 --> 00:02:16,100
But right now, just know that whether or not you write Jass or RSX in the context of create react that
25
00:02:16,610 --> 00:02:19,580
you can write in both file types.
26
00:02:20,060 --> 00:02:24,950
But we want to write docs in ours because we want to be explicit.
27
00:02:25,250 --> 00:02:31,670
We want to know that if we're going to write sex while this file type is Jass X, we're also going to
28
00:02:31,670 --> 00:02:36,110
create our search box dot styles, dot CSF.
29
00:02:37,110 --> 00:02:40,710
And I've included the stats for you, and you can find it in your resources.
30
00:02:41,730 --> 00:02:45,180
So you just want to copy that file and paste it in.
31
00:02:46,030 --> 00:02:53,200
And then you want to import it into our search box component, so let's first import react from react.
32
00:02:54,780 --> 00:02:56,700
And then let's import in our stylesheet.
33
00:02:58,910 --> 00:03:01,460
Now we're going to use another functional component.
34
00:03:02,700 --> 00:03:05,820
Now, let's go a little deeper about functional components.
35
00:03:07,430 --> 00:03:09,380
So functional components.
36
00:03:10,770 --> 00:03:14,640
Unlike class components such as our Apgar's component.
37
00:03:15,660 --> 00:03:21,540
They don't have access to state because they don't have access to constructor, which is a class method
38
00:03:21,540 --> 00:03:25,890
on our component that we import from react, that we extend our classroom.
39
00:03:26,730 --> 00:03:28,950
They also don't have access to life-cycle methods.
40
00:03:30,110 --> 00:03:37,310
They don't have internal state and life-cycle methods because we don't always need to use life-cycle
41
00:03:37,310 --> 00:03:46,700
methods or internal state, sometimes all we want to do is render some HTML and that's what a functional
42
00:03:46,700 --> 00:03:47,890
component really is.
43
00:03:48,710 --> 00:03:55,460
Unlike a class component, a functional component is just a component that gets some props and returns
44
00:03:55,460 --> 00:03:56,360
some HTML.
45
00:03:57,250 --> 00:04:05,320
And we'll figure out as we build our apps and see more challenges when to use each, but for now, the
46
00:04:05,320 --> 00:04:11,950
main thing to remember is that if you don't think you need internal state nor access to lifecycle methods,
47
00:04:12,280 --> 00:04:15,670
then just use a functional component because it's easier to read.
48
00:04:16,149 --> 00:04:19,180
It's actually easier to test, as we'll see later in the course.
49
00:04:19,690 --> 00:04:24,190
And it's in some ways smaller and easier to reason about.
50
00:04:25,120 --> 00:04:30,580
So we'll just copy over the input that we want inside of our search box component.
51
00:04:32,680 --> 00:04:40,030
We'll apply a class name of search to it, because that's where our search box styles are applying those
52
00:04:40,030 --> 00:04:40,660
styles to.
53
00:04:42,320 --> 00:04:47,930
We'll keep this type because we know that it's going to be search and then as far as placeholder goes,
54
00:04:48,110 --> 00:04:54,380
we might want this to be dynamic because maybe another place that wants to use search box doesn't want
55
00:04:54,920 --> 00:04:56,750
the placeholder to say search monsters.
56
00:04:57,200 --> 00:05:00,170
Let's say they want to search people or anything else.
57
00:05:00,740 --> 00:05:03,500
We want place to be a prop that gets passed in.
58
00:05:04,460 --> 00:05:12,590
And as we learn with our structure, we can d structure that prop off of the props object because all
59
00:05:12,590 --> 00:05:18,710
the props come in as one big objects, so let's d structure it off and then pass it into our placeholder
60
00:05:19,340 --> 00:05:25,880
and then on change can be another prop that gets passed in which is a function under the name of handle
61
00:05:25,880 --> 00:05:28,480
change and we'll just structure that one off as well.
62
00:05:29,420 --> 00:05:34,700
And then we will replace the value inside of our change right here.
63
00:05:36,980 --> 00:05:39,650
Now let's export our search box out.
64
00:05:40,830 --> 00:05:49,140
And then inside of our abcess, we can import it in and start using it, so let's import in our search
65
00:05:49,140 --> 00:05:49,500
box.
66
00:05:50,920 --> 00:05:52,150
From component's.
67
00:05:53,080 --> 00:05:53,860
Search box.
68
00:05:54,560 --> 00:05:55,520
Search box component.
69
00:05:57,730 --> 00:06:02,650
Now, in order to replace our input, we are just going to copy over.
70
00:06:03,650 --> 00:06:09,380
Some of those properties now we know that type is already on our search box component, so we don't
71
00:06:09,380 --> 00:06:09,890
need this.
72
00:06:10,960 --> 00:06:14,680
We do need the placeholder because we want to be a prop that we pass in.
73
00:06:15,860 --> 00:06:21,650
And then instead of handle on change, we're going to say handle change and then we'll pass in this
74
00:06:21,650 --> 00:06:22,070
function.
75
00:06:26,550 --> 00:06:28,140
And now let's get rid of our input.
76
00:06:28,990 --> 00:06:32,560
And if we go back to our application, we'll see, there's our search box.
77
00:06:33,470 --> 00:06:40,100
And we've still got our functionality, but now we've got a reusable component that we can use in multiple
78
00:06:40,100 --> 00:06:40,590
places.
79
00:06:41,570 --> 00:06:47,660
And this is what's great about react is this component driven style of writing code.
80
00:06:48,290 --> 00:06:55,640
Our search box is just a presentational component that pretty much styles an input and then it takes
81
00:06:55,640 --> 00:06:59,660
any functionality that it might need in its handle change property.
82
00:07:00,410 --> 00:07:03,650
But now we have this reusable search box component.
83
00:07:04,730 --> 00:07:10,730
And this is great because we can minimize the amount of repeat code that we have, we don't have to
84
00:07:10,730 --> 00:07:18,590
write an input and then style it inside of a local file because we can separate it into its own component.
85
00:07:19,430 --> 00:07:25,310
This will become much more apparent as we start building larger and larger applications where more of
86
00:07:25,310 --> 00:07:26,610
the code gets reused.
87
00:07:27,200 --> 00:07:33,050
Right now, the benefits might not be so obvious, but it's definitely the style that we want to code
88
00:07:33,050 --> 00:07:33,200
in.
89
00:07:33,380 --> 00:07:40,880
And this is one of the huge advantages of react is writing these smaller and smaller reusable components.
90
00:07:42,310 --> 00:07:44,320
OK, now let's continue.
9059
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.