text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
let's change this back to 0.
4,985.63
1.17
And so now as you notice it is showing that 0 value as expected.
4,990.8
3.485
But let's actually call this something else.
4,997.29
2.68
So let's call this custom Count.
4,999.97
2.98
So even though over here we're exporting a variable called
5,009.98
4.92
Count, since we're are using it as a default export,
5,014.9
4.89
we can import the default export in this file and call it whatever you want.
5,019.79
5.54
And so we can call it custom Count over here and it still works as expected.
5,025.33
5.06
And so the difference between named and default exports are that named, 1,
5,030.39
4.67
you can export multiple of named exports and also
5,035.06
5.4
import to multiple named exports from a different file.
5,040.46
3.96
And they do have to be named exactly as they are in the other files.
5,044.42
5.68
But when you export something default you're
5,050.1
2.15
limited to only exporting one which makes sense.
5,052.25
2.52
If you exported multiple defaults you wouldn't know which one to import.
5,054.77
4.317
And then over here, you can call it whatever
5,059.087
1.833
you want because it doesn't matter, it's just the default export.
5,060.92
5.16
And so that's how you're going to go about starting
5,066.08
2.37
to remove components from one long file and move them into separate files.
5,068.45
7.09
And so you can also actually import the export default and also named exports.
5,075.54
10.37
So here we are exporting a named export and we're also having a default export.
5,090.33
7.11
And in here we're importing the default and we're also importing a named export
5,097.44
7.9
and, as you see, that works as well.
5,105.34
2.44
And so over here you see that we are importing React from React which
5,110.72
5.2
is whatever its default export is.
5,115.92
3.57
We could also import one of its named exports,
5,119.49
5.67
and rather than extending a React.component
5,125.16
2.84
we can just extend component here because we
5,128
4.3
went ahead and imported the named export called component from React.
5,132.3
4.74
And so that will also work as well.
5,137.04
2.14
So any questions on importing and exporting
5,143.89
2.72
and how you would go about breaking up particular components
5,146.61
3.66
into separate files?
5,150.27
3.04
Yeah.
5,153.31
1
AUDIENCE: You were able to access the components with React.components.
5,154.31
6.5
Is that because the component is [INAUDIBLE] named export and the value
5,160.81
6.5
in the React.components?
5,167.31
2
SPEAKER 1: Yes exactly.
5,169.31
1
So the question was, I was able to access component
5,170.31
3.83
as React.component and separately also as component
5,174.14
7.86
and that's because this thing called component is actually
5,182
3.69
a property on this React.
5,185.69
4.56
And so what React exports is both a default export, which
5,190.25
4.11
is this massive thing where one of its object keys is called a component
5,194.36
7.29
and has the value of the component and it's also separately exporting
5,201.65
4.08
a named export called component.
5,205.73
1.86
And so we can go ahead and either import the default export and do that
5,207.59
4.27
.component or we can import the named component and just use that.
5,211.86
3.61
So you're absolutely correct.
5,215.47
1.92
Any other questions on importing and exporting?
5,221.23
2.99
Cool.
5,227.93
0.5
So when we go ahead and import and export components
5,228.43
4.42
they can start to get more and more complex as we pass down more props.
5,232.85
5.26
And so how might we go about keeping track of all of these props?
5,238.11
4.22
Well React actually has a way to help you with that,
5,242.33
3.09
and it's called prop types.
5,245.42
2.22
And so React can actually validate the types of a given components props
5,247.64
3.9
at runtime which is great.
5,251.54
2.59
It's a development tool that allows you as a developer
5,254.13
3.09
to ensure that you're passing the props that you
5,257.22
2
think you're actually passing down.
5,259.22
1.458
And so say you're passing down some prop that's a number
5,260.678
3.972
but you actually want it as a string.
5,264.65
2.1
It's very easy, as your project scales up, to kind of get those mixed up
5,266.75
5.512
and maybe you pass down a string when you meant
5,272.262
1.958
to pass down a number or vise versa.
5,274.22
3.31
And so this thing called PropTypes allows you to keep track of that.
5,277.53
4.31
And React will actually do this automatically in development mode.
5,281.84
4.75
And this is also great because it helps document your APIs.
5,286.59
2.78
And so I have this very simple component over here called Count
5,289.37
8.19
and it takes a single prop called Count.
5,297.56
2.16
But say it also took three other props and say
5,299.72
2.825
it also had 10 other components that also took their own props.
5,302.545
5.365
It might get kind of hard to remember that as I scale the project.
5,307.91
4.11
And say you're somebody like Facebook who
5,312.02
1.8
have something like 30,000 different components in production
5,313.82
3.69
it would be very painful to not have those documented
5,317.51
2.21
and have to go and read the code to know exactly what props you should
5,319.72
2.98
be passing.
5,322.7
1.45
And so by declaring this thing called PropTypes
5,324.15
3.95
you actually can help self document all of these APIs.
5,328.1
3.59
And what's nice is this only runs in development mode
5,331.69
2.23
and so you don't have to worry about it slowing down
5,333.92
2.166
your production in production mode.
5,336.086
3.604
And so how might we go about doing that?
5,339.69
2.45
There's actually a package called PropTypes.
5,342.14
2.07
It used to be bundled as part of React but they've
5,344.21
2.91
since split it into its own module though it's still
5,347.12
5.73
maintained by Facebook.
5,352.85
1.62
So we can go ahead and do this thing called import PropTypes
5,354.47
4.47
from a package called prop-types.
5,358.94
1.95
And so now we have access to this variable called PropTypes
5,364.97
2.61
where importing the default export of whatever this library called
5,367.58
6.36
PropTypes is.
5,373.94
1.63
And so now we can go ahead and use that in our file.
5,375.57
2.21
And so let's go ahead and do Count.
5,377.78
4.2
And so we created this variable called Count,
5,381.98
3.25
which is a function of a stateless functional component.
5,385.23
3.78
And we can actually attached to it a property called propTypes.
5,389.01
6.48
Note that it's a lower case p here.
5,395.49
2.3