text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
And I can set it equal to an
object and the keys of this object | 5,401.05 | 3.33 |
will map to whatever
props that I expect. | 5,404.38 | 3.31 |
And so in this case we expect
a single prop called Count. | 5,407.69 | 3.9 |
And so I can say Count should
be of what type, well PropTypes. | 5,411.59 | 4.8 |
So capital P here is referring to
the library that we just imported. | 5,416.39 | 4.09 |
And we can say we want a
number, and it's required. | 5,420.48 | 4.24 |
And so now we see this warning. | 5,428.14 | 5.49 |
We see, hey, there's a
failed prop type here. | 5,433.63 | 4.77 |
The prop count is marked as
required in this component | 5,438.4 | 3.54 |
called Count but it's values undefined. | 5,441.94 | 2.49 |
Why is it undefined? | 5,444.43 | 1.69 |
Well because we're importing
this thing called number | 5,446.12 | 3.71 |
and we're passing this thing
called number over here. | 5,449.83 | 2.31 |
But we're not actually exporting
anything called number in this module. | 5,452.14 | 4.51 |
And say we actually remove
that and passed a 0 here. | 5,456.65 | 7.34 |
Now it'll run as expected. | 5,466.54 | 1.71 |
There are no warnings thrown. | 5,468.25 | 2.91 |
And now let's try simulating a mistake
where rather than passing the number 0 | 5,471.16 | 5.22 |
we go ahead and pass the string 0. | 5,476.38 | 4.32 |
The app will still work because we're
just displaying whatever we pass. | 5,480.7 | 4.47 |
But if you notice we
have a warning here. | 5,485.17 | 4.11 |
Warning: Failed prop type. | 5,489.28 | 1.29 |
Invalid prop count of type
string supplied to count. | 5,490.57 | 3.24 |
We were actually expecting a number. | 5,493.81 | 1.825 |
And so that's actually
React's built-in prop type | 5,495.635 | 2.675 |
system which is checking against the
types that we're passing down here. | 5,498.31 | 4.08 |
We say, hey we're expecting
this thing as a number | 5,502.39 | 2.92 |
but since we pass a string it will throw
a warning for us just to let us know, | 5,505.31 | 3.635 |
oh by the way I don't know
if you know this or not, | 5,508.945 | 2.125 |
but you're passing the wrong type down. | 5,511.07 | 2.25 |
And so we can use this thing
called prop types in order | 5,513.32 | 2.39 |
to validate the props that were passed. | 5,515.71 | 5.162 |
And so in stateless
functional components | 5,520.872 | 1.708 |
we actually just add this as a property. | 5,522.58 | 3.33 |
But say this were actually
a class component. | 5,525.91 | 3.81 |
So let's do class Count,
extends React.component. | 5,529.72 | 12.96 |
And then we have a render
which will just return this. | 5,542.68 | 5.357 |
And let's fix some styling
so it's easier to read. | 5,553.35 | 2.16 |
So now we have a class component and
as long as there are no syntax errors-- | 5,560.5 | 7.76 |
There's a syntax error
somewhere that I don't see. | 5,571.06 | 6.16 |
Does anybody see the syntax error? | 5,577.22 | 1.51 |
Can anybody beat me to it? | 5,578.73 | 1.693 |
AUDIENCE: Is that last a
parentheses or is that a bracket? | 5,580.423 | 3.099 |
SPEAKER 1: This here is a parentheses. | 5,583.522 | 1.583 |
Oh, yep. | 5,585.105 | 2.595 |
Nice catch. | 5,587.7 | 0.745 |
I owe you some candy. | 5,588.445 | 0.875 |
So now if we go ahead
and reload this, it | 5,592.08 | 3.3 |
can't find the called props
because class component | 5,595.38 | 6.51 |
is stored as this.props. | 5,601.89 | 2.13 |
And now we can go ahead and
see that it is as expected. | 5,604.02 | 3.789 |
We still have that
failed prop type message | 5,607.809 | 1.791 |
because we're passing a string rather
than a number but it's working. | 5,609.6 | 4.38 |
And so we can go ahead and
so we create the class here. | 5,613.98 | 3.7 |
And then we go ahead and do
Count.propTypes here which works. | 5,617.68 | 3.84 |
But generally the way that you
see the convention is actually | 5,621.52 | 4.52 |
to use this thing
called a static method. | 5,626.04 | 3.55 |
And so there's actually a static keyword
where you can do static propTypes | 5,629.59 | 5.35 |
equals that object. | 5,634.94 | 1.69 |
So functionally exactly the same, but
the convention is to use this thing | 5,642.09 | 5.27 |
called a static method
or a static property | 5,647.36 | 5.88 |
because it's just the way that
the new class index works. | 5,653.24 | 5.53 |
And so it's functionally the same
as doing count.propTypes down here, | 5,658.77 | 4.57 |
but the convention is just
to use the newer syntax. | 5,663.34 | 2.125 |
So any questions on PropTypes? | 5,668.49 | 3.38 |
Does everybody see the
utility of using them? | 5,671.87 | 2.85 |
They've definitely saved me
multiple times on personal projects. | 5,674.72 | 2.865 |
And so now, if we've passed the
correct props, there are no warnings. | 5,683.83 | 6.22 |
Great. | 5,690.05 | 0.5 |
And the last concept I wanted to touch
on is just how the heck do I read docs. | 5,690.55 | 5.515 |
Because I can't possibly teach
you every single component | 5,696.065 | 2.375 |
that React Native offers. | 5,698.44 | 1.74 |
But they do offer a
lot of great components | 5,700.18 | 2.34 |
that you may want to use in either
project for this class or maybe | 5,702.52 | 3.48 |
a personal project
that you're working on. | 5,706 | 1.98 |
And so here's basically
the steps that I go through | 5,707.98 | 3.15 |
in order to figure out what I should
use when working on my own project. | 5,711.13 | 4.09 |
So first have a goal in mind. | 5,715.22 | 1.832 |
You need to know what problem
you're trying to solve. | 5,717.052 | 2.208 |
Otherwise reading a bunch
about what's offered | 5,719.26 | 2.31 |
doesn't really mean anything to you. | 5,721.57 | 1.86 |
And so say you were doing
something like the TODO app | 5,723.43 | 3.09 |
that we did before the first
thing that you'll notice | 5,726.52 | 3.6 |
is that there is no input
type checkbox in React Native. | 5,730.12 | 3.7 |
And so you have to figure
out what is my goal here? | 5,733.82 | 2.57 |
Well I want to replace
what used to be a checkbox. | 5,736.39 | 4.91 |
And so your goal in that
example would be all right | 5,741.3 | 2.77 |
I need some component that
basically just renders a Boolean. | 5,744.07 | 4.62 |
Then just see what the
library or framework offers. | 5,748.69 | 2.72 |
And so the way I did that was I
just browsed through the docs. | 5,751.41 | 3.77 |
So they're linked in this presentation. | 5,755.18 | 2.87 |
I'll go ahead and link them in
the Resources tab on the website. | 5,758.05 | 3.51 |
But just see exactly what the library
has to offer, see what they have, | 5,761.56 | 4.755 |
then find something that
solves your problem. | 5,766.315 | 1.875 |
There may be multiple things
that solve your problem | 5,768.19 | 2.19 |
but just try to find the thing
that best solves your problem. | 5,770.38 | 2.88 |
And so in my case for that
particular Boolean switch | 5,773.26 | 3.09 |
I saw that they had something
called a switch that | 5,776.35 | 2.49 |
just renders a Boolean flag that you
can just tap and then configure it. | 5,778.84 | 8.43 |
And so the docs will
tell you exactly what | 5,787.27 | 2.73 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.