text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
---|---|---|
out the information for each slide. | 1,578.93 | 4.96 |
And so now let's go ahead
and implement that slideshow. | 1,583.89 | 3.652 |
And so in order to do
that, we might have | 1,587.542 | 1.708 |
something like where we have a
slide, which might take an array, | 1,589.25 | 10.52 |
or it might take an object. | 1,599.77 | 1.26 |
Let's call it a slide. | 1,601.03 | 2.916 |
And what will it return? | 1,603.946 | 2.454 |
Well, it should return a div. | 1,606.4 | 3.597 |
Maybe inside it we have that H1. | 1,609.997 | 1.333 |
Then maybe we have that unordered list. | 1,615.16 | 1.64 |
And then go ahead and close that div. | 1,619.359 | 1.541 |
So what goes in the H1 here? | 1,626.26 | 2.37 |
Well, maybe we should
have that slide's title. | 1,628.63 | 5.31 |
And what about generating those bullets? | 1,633.94 | 2.1 |
Well, like we did in
the previous example, | 1,636.04 | 1.75 |
we might want to do the
slide.bullets and map [? overflows ?] | 1,637.79 | 4.01 |
to create those list items. | 1,641.8 | 2.16 |
So for each bullet, just go
ahead and create a list item | 1,643.96 | 6.196 |
where you have that bullet. | 1,650.156 | 1.124 |
And so now we declared
exactly what a slide is. | 1,657.25 | 2.48 |
Well, a slide takes in
an object representing | 1,659.73 | 2.79 |
the slide in the same shape
of the object up here. | 1,662.52 | 6.03 |
And then it just returns the same
HTML that we had in the other example. | 1,668.55 | 3.81 |
It's a div that wraps
in H1, where we stick | 1,672.36 | 2.04 |
in the title, an unordered
list that has some list | 1,674.4 | 3.06 |
items that represent those bullets. | 1,677.46 | 2.409 |
And now how might we
create that slideshow? | 1,679.869 | 1.791 |
Well, maybe we just do for
each slot in the slides, | 1,688.45 | 7.08 |
maybe we have an outer-wrapping
div that maps through the slides. | 1,695.53 | 7.44 |
And for each slide, we actually
just use the slide down there. | 1,705.79 | 5.23 |
So now we're going to get ahead
and use React and generate | 1,724.29 | 5.36 |
basically the same HTML as
we had in the previous one. | 1,729.65 | 3.12 |
But now say we wanted to change
the styling of the title. | 1,732.77 | 3.33 |
How would we do that? | 1,736.1 | 1.48 |
Well, that's just right here. | 1,737.58 | 2.33 |
What about if we wanted to
change the structure of how | 1,739.91 | 2.25 |
we created those bullets? | 1,742.16 | 2.64 |
In the previous example, if we wanted
to wrap the list items in a div, | 1,744.8 | 3.469 |
it would be many, many lines of code. | 1,748.269 | 1.541 |
But here, it's just
you stick a div here, | 1,749.81 | 2.79 |
because this is basically an
abstract component that says, | 1,752.6 | 3.18 |
if we wanted to create a slide,
here's exactly how we do it. | 1,755.78 | 2.52 |
Just make sure to pass me a
slide of the correct shape. | 1,758.3 | 4.2 |
And so the React paradigm is
to take a very complex problem | 1,762.5 | 3.3 |
and break it down into
small chunks like this | 1,765.8 | 2.28 |
that each solve a discrete
problem in that UI. | 1,768.08 | 4.29 |
Any questions so far? | 1,772.37 | 1.23 |
Cool. | 1,781.3 | 0.8 |
So another great thing is
that React is very performant. | 1,782.1 | 3.29 |
We just write what we
want, and React will | 1,785.39 | 1.75 |
do the hard work of
playing with the DOM, | 1,787.14 | 2.67 |
or changing things so
that what we have written | 1,789.81 | 3.33 |
matches with what we
have showing on the page. | 1,793.14 | 3.34 |
And so the way it does this is through
an algorithm called reconciliation. | 1,796.48 | 7.1 |
And this is the process by which
React syncs any changes in app state | 1,803.58 | 3.06 |
to the DOM. | 1,806.64 | 1.92 |
So what's great about
React is that it actually | 1,808.56 | 2.64 |
maintains what's called a virtual DOM. | 1,811.2 | 2.67 |
And so the slow thing
about playing with the DOM | 1,813.87 | 3.3 |
is that anytime you destroy elements
or create new elements, that | 1,817.17 | 3.45 |
takes a relatively long amount of time. | 1,820.62 | 3.33 |
And so the way that React
says, maybe we should do this | 1,823.95 | 3.36 |
better by rather than
changing stuff in the DOM | 1,827.31 | 2.779 |
every time we want to change something,
what if we just stored everything | 1,830.089 | 3.041 |
in memory? | 1,833.13 | 1.009 |
And then with any
changes, we can just say, | 1,834.139 | 1.791 |
hey, how does this differ
from what's shown on the page? | 1,835.93 | 2.53 |
And only change what's necessary. | 1,838.46 | 2.03 |
And so that's what's done in
the reconciliation process. | 1,840.49 | 3.03 |
So first, anytime your
data changes, React | 1,843.52 | 3.11 |
will reconstruct that virtual DOM. | 1,846.63 | 3.12 |
Then it will diff that DOM against
what's actually there in the real DOM. | 1,849.75 | 6.12 |
And it'll make only the
changes that are needed. | 1,855.87 | 2.784 |
Of course, there is an asterisk
that goes along with that, | 1,858.654 | 2.416 |
but in your mental model,
you can just think of it | 1,861.07 | 2.083 |
as React will just only make
the changes as necessary. | 1,863.153 | 5.377 |
So how the heck do we write React? | 1,868.53 | 3 |
Well, there's this
thing called JSX, which | 1,871.53 | 2.46 |
is short for JavaScript and XML, which
is basically just an XML-like syntax | 1,873.99 | 4.44 |
extension of JavaScript. | 1,878.43 | 2.349 |
It's great because it just
transpiles directly to JavaScript. | 1,880.779 | 2.541 |
So as we talked about
in an earlier lecture, | 1,883.32 | 2.7 |
the paradigm now is to rather than just
writing JavaScript by hand, using ES5 | 1,886.02 | 4.26 |
directly, we can write
in these other languages | 1,890.28 | 2.31 |
that just transpile back to JavaScript. | 1,892.59 | 2.64 |
So JSX is an extension to that
JavaScript syntax, which will just | 1,895.23 | 3.63 |
compile back down into JavaScript. | 1,898.86 | 2.7 |
And so tags defined in JSX, XML looks
exactly like HTML with the tags. | 1,904.99 | 6.06 |
Lowercase tags are treated
as HTML or SVG tags, | 1,911.05 | 3.69 |
whereas things uppercase are
treated as our custom components. | 1,914.74 | 4.136 |
And what the heck is a component? | 1,918.876 | 1.374 |
Well, a component is just a function,
a function that returns a node. | 1,920.25 | 3.387 |
What's a node? | 1,923.637 | 0.583 |
It's something that React can render. | 1,924.22 | 2.04 |
For example, like a div or a
span or a string or a number. | 1,926.26 | 3.99 |
And components will receive
an object of properties | 1,933.31 | 3.51 |
that are passed to this element. | 1,936.82 | 2.25 |
So going back to the example
that we were doing before, | 1,939.07 | 3.15 |
see how one, we declared a
const called slide down here. | 1,942.22 | 5.24 |
And notice how I
uppercased that S. That was | 1,947.46 | 2.35 |