text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
---|---|---|
fully intentional, because in
JSX, a tag with a capital S gets | 1,949.81 | 5.22 |
invoked like a function. | 1,955.03 | 1.44 |
And what does it get invoked with? | 1,956.47 | 1.68 |
Well, anything you
pass it as properties. | 1,958.15 | 2.189 |
So if you remember properties
from HTML, you just | 1,960.339 | 2.041 |
pass them in line with
the key and a value pair. | 1,962.38 | 3.57 |
In React, you do the exact
same thing, and it actually | 1,965.95 | 2.25 |
gets passed as an object to the
component that you described. | 1,968.2 | 4.549 |
And so now to talk about props. | 1,977.8 | 1.544 |
Well, props are just past as
an object through a component | 1,979.344 | 2.416 |
and used to compute the return node. | 1,981.76 | 1.5 |
So basically, the object that we were
just referring to in this example, | 1,983.26 | 3.84 |
we called it a slide. | 1,987.1 | 2.08 |
In React convention, we always call
that props, short for properties, | 1,989.18 | 3.41 |
like those HTML properties. | 1,992.59 | 4.26 |
And any change to these props will cause
a recomputation of that return node, | 1,996.85 | 4.35 |
or in React vocab, a re-render. | 2,001.2 | 5.2 |
And so unlike in HTML, these
can be any JavaScript value. | 2,006.4 | 2.97 |
So if you remember back to HTML,
when you declare a property, | 2,009.37 | 3.37 |
it has to be a string. | 2,012.74 | 1.27 |
It might be JavaScript,
like a JavaScript function, | 2,014.01 | 4.44 |
but really it's just a string. | 2,018.45 | 2.05 |
And so you can't pass any complex
objects or a date, object, classes, | 2,020.5 | 5.75 |
instances, and stuff like that. | 2,026.25 | 2.07 |
But in React, we can pass anything. | 2,028.32 | 1.62 |
So notice here, slide is an
object as declared in the array | 2,029.94 | 5.864 |
that we have up there. | 2,035.804 | 0.916 |
And we're just passing
the object over there. | 2,036.72 | 2.88 |
And the way that we pass
values in JavaScript | 2,039.6 | 2.22 |
is we wrap them in single
curlies, which means, | 2,041.82 | 3.53 |
hey, execute this as a JavaScript. | 2,045.35 | 2.55 |
Does that makes sense? | 2,051.594 | 0.916 |
So let's actually use
a live example of this. | 2,056.88 | 3.5 |
So there's this website
called codesandbox.io, | 2,060.38 | 2.58 |
which is linked on the
website in the Resources tab, | 2,062.96 | 4.44 |
and this allows us to write React
and actually render it live. | 2,067.4 | 4.5 |
And so can everybody read this? | 2,071.9 | 5.16 |
So basically, what's on the left
over there is code that gets executed | 2,081 | 3.719 |
and runs live on the right side here. | 2,084.719 | 1.661 |
So if we started editing this, you see
it applied directly on the right side | 2,086.38 | 6.85 |
there. | 2,093.23 | 2.32 |
And so you see we have
a const called app, | 2,095.55 | 2.862 |
which doesn't care
about any arguments it | 2,098.412 | 1.708 |
receives and just renders
the static HTML here. | 2,100.12 | 6.12 |
So what if we actually
wanted to pass it a prop? | 2,106.24 | 2.38 |
So say we passed it something like
a count and passed it the number 1. | 2,108.62 | 7.43 |
Again, we use curly braces there to
represent this is JavaScript coming, | 2,116.05 | 5.07 |
and the JavaScript is just the number 1. | 2,121.12 | 3.06 |
So how might we go ahead
and render that in the app? | 2,124.18 | 4.23 |
Well, first, we need to actually
pay attention to the object | 2,128.41 | 4.016 |
that we receive here. | 2,132.426 | 0.874 |
And second, we can just
do it directly in line. | 2,136.86 | 3.96 |
And so we use those curly
braces to represent, | 2,140.82 | 3.9 |
hey, here comes some JavaScript. | 2,144.72 | 2.13 |
And we can just use
props.count, and now we'll | 2,146.85 | 5.23 |
go ahead and grab the prop with
the key [? call ?] account. | 2,152.08 | 7.08 |
And so I mentioned that as props
change, React gets re-rendered. | 2,159.16 | 3.57 |
So how might we do that? | 2,162.73 | 1 |
Well, we can just wrap this in a set
timeout, or a set interval, rather. | 2,166.81 | 4.72 |
And every 1,000 milliseconds
or 1,000 milliseconds, | 2,175.53 | 5.07 |
let's go ahead and pass it not
just one, but the count plus plus, | 2,180.6 | 7.08 |
where count starts at 0. | 2,187.68 | 5.13 |
And every time this is
invoked, it increments. | 2,192.81 | 6.86 |
And so down here, we're
saying, sudden interval, | 2,202.96 | 2.2 |
which means run some
function every n seconds. | 2,205.16 | 2.42 |
We set n to equal 1,000
milliseconds, or one second there. | 2,207.58 | 4.57 |
And every time we want
to render this function | 2,212.15 | 2.66 |
called app with a count of one
more than it was last time. | 2,214.81 | 5.091 |
And so we start at 0,
and every second you | 2,219.901 | 1.749 |
see we pass a new prop
count incremented. | 2,221.65 | 5.91 |
And even though we're not really doing
anything actively in the app here, | 2,227.56 | 4.77 |
we wrote this in a very
declarative nature, right? | 2,232.33 | 2.36 |
We said, for any props that you give
me, just render a div with an H2 where | 2,234.69 | 6.43 |
the H2 is the value of the props. | 2,241.12 | 1.807 |
See how that's very declarative. | 2,242.927 | 1.333 |
We don't say, oh, first
you have to grab the count, | 2,244.26 | 3.749 |
then check to see if it is
different than the last one, | 2,248.009 | 2.291 |
and then append this to the DOM. | 2,250.3 | 1.333 |
We just say, hey, this is what we want. | 2,251.633 | 1.637 |
And React will give it to us. | 2,253.27 | 3.12 |
Any questions on React
or props thus far? | 2,256.39 | 4.71 |
Yeah? | 2,261.1 | 0.695 |
AUDIENCE: [INAUDIBLE] | 2,261.795 | 3.805 |
JORDAN HAYASHI: Yes, of course. | 2,265.6 | 1.71 |
So set interval requires two arguments,
where the first one is a function. | 2,267.31 | 15 |
So the question was can you go
over the arrow notation here? | 2,282.31 | 5.29 |
And so set interval
expects two arguments. | 2,287.6 | 2.91 |
One is a function that it
will invoke with no arguments, | 2,290.51 | 3.98 |
and so I'm just declaring an anonymous
function here with no arguments. | 2,294.49 | 3.63 |
So I'm saying, here is a
function that takes no arguments, | 2,298.12 | 3.085 |
and what should I do? | 2,301.205 | 0.875 |
Well, I should render this. | 2,302.08 | 1.71 |
I could have also written this as
this, and it would have functionally | 2,303.79 | 12.297 |
been the exact same. | 2,316.087 | 0.833 |
Does that makes sense? | 2,328.614 | 0.916 |
Any other questions on React or props? | 2,332.27 | 2.7 |
Yeah? | 2,334.97 | 0.593 |
AUDIENCE: So in line 10 [INAUDIBLE]? | 2,335.563 | 2.465 |
JORDAN HAYASHI: So in line 10, we
have braces after the arrow here. | 2,344.93 | 5.72 |
So that's just saying, interpret
all of this as one statement. | 2,350.65 | 5.72 |
Subsets and Splits