text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
And then after it re-invokes
the function and returns nodes, | 2,041.87 | 3.2 |
React will do its thing and compare
nodes to what it has in its virtual dom | 2,045.07 | 4.407 |
and then go ahead and
replace what's needed. | 2,049.477 | 1.833 |
And so on the other side of the coin,
we have what's called a React.component. | 2,054.06 | 3.966 |
This is something that's actually
provided by the React library | 2,058.026 | 2.624 |
and implemented for you. | 2,060.65 | 1.68 |
And it's an abstract class that can be
extended to behave however you want. | 2,062.33 | 3.82 |
And so, in our example
here and examples prior, | 2,066.15 | 3.299 |
we've been doing this thing where we
create a class called whatever we want | 2,069.449 | 3.421 |
and we're actually extending this
thing called a React component. | 2,072.87 | 4.53 |
And so what is a React.component? | 2,077.4 | 3.981 |
Well these things have
additional features | 2,081.381 | 1.749 |
that stateless functional
components do not. | 2,083.13 | 2.46 |
One of those, of course, is that they
have instances so they're a class. | 2,085.59 | 3.247 |
And so when you invoke that
class it returns an instance | 2,088.837 | 2.333 |
and that instance will persist
throughout the lifetime of this class. | 2,091.17 | 5.719 |
As suggested by the name,
it maintains its own state | 2,096.889 | 3.341 |
and so stateless components do not,
whereas these React components do. | 2,100.23 | 4.62 |
They have this concept of
state, and we talked about state | 2,104.85 | 2.58 |
in depth last lecture. | 2,107.43 | 0.96 |
One thing we didn't
talk about last lecture | 2,111.399 | 1.791 |
is this thing called a lifecycle,
it's lifecycle methods. | 2,113.19 | 3.395 |
And so these are similar
to hooks or event handlers. | 2,116.585 | 2.595 |
And so we've used the event handlers
before in both React Web and React | 2,119.18 | 4.17 |
Native. | 2,123.35 | 1.29 |
And these things are actually
automatically invoked for you. | 2,124.64 | 2.56 |
You don't have to worry about
exactly the implementation details | 2,127.2 | 3.65 |
or when to invoke your own functions. | 2,130.85 | 1.9 |
That's actually something
that's done automatically. | 2,132.75 | 4.13 |
And so unlike stateless
functional components, | 2,136.88 | 2.43 |
which just take props and return a
node, a React components render function | 2,139.31 | 4.68 |
actually becomes a function of
the props and also any class | 2,143.99 | 3.06 |
properties that exist. | 2,147.05 | 1.06 |
And so if you remember back to last
lecture we talked about classes | 2,148.11 | 3.44 |
and how when you create
a class instance, | 2,151.55 | 1.96 |
you might attach to it some properties. | 2,153.51 | 2.1 |
These properties can be
values anywhere from functions | 2,155.61 | 3.23 |
to just primitives, objects. | 2,158.84 | 3.78 |
And so when you create a
class component instance, | 2,162.62 | 3.19 |
you can actually use all of those
class properties in that render method. | 2,165.81 | 5.85 |
And so we saw that over here
when we created this addTODO | 2,171.66 | 7.04 |
where within the render we referenced
this.addTODO in this button component | 2,178.7 | 6.99 |
here. | 2,185.69 | 1.401 |
And so, as you see, this is a
class property which we actually | 2,187.091 | 3.249 |
used in our render method. | 2,190.34 | 1.56 |
And so this render method is
actually a function of both props | 2,191.9 | 4.29 |
and any class properties like its
state or these methods that we defined. | 2,196.19 | 5.33 |
Cool. | 2,204.72 | 0.5 |
So I talked about this thing
called a lifecycle method, | 2,205.22 | 2.74 |
but what actually is
a component lifecycle. | 2,207.96 | 3.08 |
And so a component lifecycle can
actually be represented by this graph. | 2,211.04 | 3.89 |
And so first a component will
mount and so some lifecycle hooks | 2,214.93 | 4.48 |
get called there, but that's
basically that constructor where | 2,219.41 | 4.06 |
the class instance gets created and
maybe its state gets instantiated. | 2,223.47 | 5.48 |
And then what it does is it renders. | 2,228.95 | 2.4 |
It will just put you to the page. | 2,231.35 | 3.03 |
And then every time we call set
state or get new props we actually | 2,234.38 | 3.21 |
enter what's called an update cycle. | 2,237.59 | 1.78 |
And so when you receive new props,
the component needs to update. | 2,239.37 | 2.97 |
It needs to re-render. | 2,242.34 | 1.44 |
And so part of its lifecycle is
actually updating over and over. | 2,243.78 | 3.69 |
And this happens any time new props
get received because it wouldn't really | 2,247.47 | 3.53 |
make sense if we had
a component that when | 2,251 | 2.13 |
it received new props nothing changed. | 2,253.13 | 2.61 |
But also this update cycle happens
every single time the state changes. | 2,255.74 | 3.88 |
So if you call this .setstate, you
update state and presumably you have | 2,259.62 | 4.19 |
something in the UI that also updates. | 2,263.81 | 1.74 |
And so this update
cycle will happen again. | 2,265.55 | 2.04 |
And every single time you update state,
receive new props this update cycle | 2,267.59 | 3.43 |
will fire again. | 2,271.02 | 1.67 |
And then, when it's time for
that component to disappear, | 2,272.69 | 2.96 |
it enters what's called
the unmount stage where | 2,275.65 | 3.91 |
you have the chance to
clean up anything that you | 2,279.56 | 3 |
may have created during that lifecycle. | 2,282.56 | 4.44 |
And so what actually does
that mean in practice? | 2,287 | 3.652 |
So I said that there's
this thing called mount, | 2,290.652 | 1.958 |
which is basically
just a series of steps | 2,292.61 | 2.04 |
that happens when a component
first gets mounted and rendered. | 2,294.65 | 3.189 |
And so the first thing that happens
is the constructor gets called. | 2,297.839 | 2.791 |
And so, as we saw a few lectures
ago when we talked about classes, | 2,300.63 | 3.35 |
the constructor is where we have
a chance to add class properties | 2,303.98 | 4.11 |
or add anything to that
instance that we need. | 2,308.09 | 3.3 |
And so here we might want to
do stuff like initialize state | 2,311.39 | 2.52 |
or maybe add some other class
properties like bound methods et cetera. | 2,313.91 | 5.52 |
Next what happens is we render, which
is just the meat of the component. | 2,319.43 | 5.33 |
The main goal of any
component is to show you why. | 2,324.76 | 4.24 |
And so, in this render method,
that's exactly what happens. | 2,329 | 4.08 |
You take any properties that you have,
any class properties that you have, | 2,333.08 | 4.66 |
and then you end up returning a node. | 2,337.74 | 3.209 |
And then after that this hook,
that we haven't seen yet, gets | 2,340.949 | 2.541 |
called a component div mount. | 2,343.49 | 1.646 |
And this is the chance
for you to do anything | 2,345.136 | 1.874 |
that you wanted to do that
didn't really matter for render. | 2,347.01 | 4.285 |
And so if you have asynched actions,
like standing network or passes. | 2,351.295 | 2.875 |
If you want to add timers
and stuff like that this | 2,354.17 | 3.57 |
is exactly where you should do that. | 2,357.74 | 3.31 |
And then maybe you'll need to
update the state accordingly. | 2,361.05 | 3.32 |
And so if you actually
see that state here | 2,364.37 | 2.01 |
this will cause a re-render
without updating the UI. | 2,366.38 | 2.36 |
And so all of this will happen
before the UI re-renders. | 2,368.74 | 3.57 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.