text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
|---|---|---|
We're going to have a
button called delete.
| 4,287.66
| 1.43
|
It doesn't actually do anything for now.
| 4,289.09
| 1.99
|
And we also have a span, and
what's that value of the span?
| 4,291.08
| 3.29
|
Well, just look at my
props and grab the text.
| 4,294.37
| 2.35
|
OK, so now what do we have to do?
| 4,307.39
| 1.5
|
Maybe we should add a way to add to dos.
| 4,308.89
| 3.49
|
So let's create a
method called add to do.
| 4,312.38
| 5.205
|
And what should we do first?
| 4,317.585
| 1.475
|
Maybe we should get some text.
| 4,319.06
| 2.53
|
So there are many
different ways to do this.
| 4,321.59
| 6.01
|
Let's just for now prompt.
| 4,327.6
| 1.408
|
And then what do we
want to do with that?
| 4,340.48
| 2.34
|
We have text.
| 4,342.82
| 2.34
|
What should we actually do with it?
| 4,345.16
| 2
|
AUDIENCE: Add it to the to do list.
| 4,351.66
| 2
|
JORDAN HAYASHI: Yeah, we should
add it to our to do list.
| 4,353.66
| 1.77
|
And how are we going to do that?
| 4,355.43
| 1.333
|
We can just do this dot state
equals something, right?
| 4,359.22
| 2.54
|
No.
| 4,364.28
| 0.51
|
There's only one way
to update state, right?
| 4,364.79
| 1.833
|
We should do this dot set state.
| 4,366.623
| 2.711
|
And what are we doing?
| 4,369.334
| 0.916
|
Well, we have the to do equal
this dot state dot to dos.
| 4,370.25
| 11.13
|
And then additional thing.
| 4,381.38
| 2.22
|
And so the way that
we've added to an array
| 4,383.6
| 3.12
|
thus far is by doing
this sum array dot push.
| 4,386.72
| 3.87
|
What that does is it
actually mutates the array.
| 4,390.59
| 3.06
|
And so the way that React
knows that it should update
| 4,393.65
| 4.11
|
is it sees if the values that
are passed to it are different.
| 4,397.76
| 4.69
|
And as we learned a couple
lectures ago, all objects
| 4,402.45
| 2.666
|
are actually stored by reference.
| 4,405.116
| 1.374
|
And so when we go ahead
and mutate an object,
| 4,406.49
| 3.297
|
the reference doesn't actually change.
| 4,409.787
| 1.583
|
And so the React paradigm is
rather than mutating these props,
| 4,411.37
| 3.7
|
we should actually create new ones.
| 4,415.07
| 2.71
|
And so a quick way to
create a new array is
| 4,417.78
| 5.45
|
by using this dot dot
dot notation, which
| 4,423.23
| 1.92
|
means given an array, if
you dot dot dot array,
| 4,425.15
| 5.28
|
it just pulls out all of
those values of the array.
| 4,430.43
| 3.24
|
And so when we do something like
brackets dot dot dot some array,
| 4,433.67
| 5.43
|
it pulls out all the values of that
array and puts it into a new array.
| 4,439.1
| 3.6
|
And so this is a quick
way of cloning an array.
| 4,442.7
| 2.741
|
And so now the array reference is
changed, but the values in there
| 4,445.441
| 2.749
|
are all the same.
| 4,448.19
| 2.2
|
And so now we've cloned the array,
and now we should add a new to do.
| 4,450.39
| 6.11
|
And so let's call our to dos
objects that have a text field,
| 4,456.5
| 6.88
|
and that can be the text.
| 4,463.38
| 1.422
|
So there's a small bug
in our program now.
| 4,469.89
| 1.95
|
Well, one, we don't
know how to add a list.
| 4,471.84
| 3
|
Add to that.
| 4,474.84
| 1.33
|
So let's go ahead and create
a button that can add a to do.
| 4,476.17
| 8.862
|
So now you have a button,
but it's not actually
| 4,485.032
| 1.958
|
doing anything when we click it.
| 4,486.99
| 2.25
|
So first we need to set
up an event handler,
| 4,489.24
| 4.83
|
so when that button is
clicked, what should it do?
| 4,494.07
| 3.71
|
Well, it should do this dot add to do.
| 4,497.78
| 4.935
|
So what is wrong with this code?
| 4,502.715
| 1.9
|
Why isn't it working?
| 4,508.89
| 3.05
|
Yeah, this is not bound
to what it should be.
| 4,511.94
| 1.94
|
And so how are we going to fix that?
| 4,513.88
| 1.94
|
Well, the easiest way is
to just declare an arrow
| 4,515.82
| 2.34
|
function in line here, which will
lexically bind what we want it to do.
| 4,518.16
| 7.75
|
And so now we have another
bug, so we declared
| 4,525.91
| 4.84
|
to do to be a list item with
an input, a button, and a span.
| 4,530.75
| 4.49
|
And we see the input in the
button, but we don't see any spans.
| 4,535.24
| 3.67
|
So does anybody spot exactly
why that's happening?
| 4,538.91
| 4.049
|
So what text are we
populating that span with?
| 4,551.77
| 2.916
|
Props dot text.
| 4,561.87
| 1.79
|
And so what does the
object called props--
| 4,563.66
| 3.84
|
what values are in there?
| 4,567.5
| 2.43
|
They're key value pairs that are
mapped to what are passed in here.
| 4,569.93
| 4.41
|
Are we passing a key
called text into to do?
| 4,574.34
| 3.42
|
No, we're not.
| 4,580.177
| 0.583
|
We're only passing something
called to do, right?
| 4,580.76
| 2.041
|
To do may have a value
called text, but in order
| 4,585.3
| 3.69
|
to actually access that, what we would
have to do is to do props.todo.text.
| 4,588.99
| 4.2
|
And that will allow us to
pull up the correct field.
| 4,596.58
| 3.84
|
So now we have a way to add to dos.
| 4,604.41
| 3.66
|
Great.
| 4,608.07
| 1.05
|
That doesn't make much of a to do app.
| 4,609.12
| 3.15
|
We should be able to check
and uncheck, which we can.
| 4,612.27
| 3.3
|
But we're not really
handling that in state.
| 4,615.57
| 2.07
|
We have no way of telling whether
these to dos are checked or not,
| 4,617.64
| 4.832
|
and we also have no
way to delete to dos.
| 4,622.472
| 1.708
|
And so we need some sort of way
to recognize which to do is which.
| 4,627.88
| 6.49
|
What are some strategies
to go about doing that?
| 4,634.37
| 3.351
|
Can anybody think of one?
| 4,637.721
| 2.959
|
AUDIENCE: [INAUDIBLE]
| 4,640.68
| 1.43
|
JORDAN HAYASHI: Yeah, we
should give each one an ID.
| 4,642.11
| 2.166
|
That way, if we can guarantee
that those IDs are unique,
| 4,644.276
| 2.444
|
then we'll have a unique way
of recognizing each to do.
| 4,646.72
| 3.94
|
And so let's go ahead
and do that real quick.
| 4,650.66
| 3.13
|
So a very easy way to do that would
be to do something like this--
| 4,653.79
| 3.45
|
have some value called ID declared
outside, initialized to 0.
| 4,661.73
| 6.18
|
And every time you create a new
one, you just increment that.
| 4,667.91
| 5.208
|
And so now every single time we
add a to do, it has an ID field.
| 4,677.38
| 3.099
|
And we're guaranteed that
it's unique, since it's
| 4,680.479
| 2.041
|
a counter outside the state of our app.
| 4,682.52
| 4.17
|
Does that makes sense?
| 4,686.69
| 2.24
|
So how does that help us?
| 4,688.93
| 1.96
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.