text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
And so now that keeps track of whether a to do is checked or not.
5,109.9
5.39
But the problem is we're not actually updating our app state every time
5,115.29
3.1
a to do is checked or not.
5,118.39
1.82
And so we're going to have to actually handle every single time
5,120.21
4.08
an input is clicked.
5,124.29
1.71
Every single time it changes, we need to update our app state accordingly,
5,126
4.35
because if you look here, I'm clicking but nothing is happening.
5,130.35
8.649
Why is nothing happening?
5,138.999
1.041
Well, we're initializing our to dos to be checked if false.
5,140.04
4.47
We're saying, for each to do, make sure that checkbox, whether it's checked
5,144.51
4.14
or not, is whether that to do--
5,148.65
2.58
its check value is true or false.
5,151.23
1.619
But we have no way to change that from not false,
5,152.849
2.041
and so no matter how many times I click that,
5,154.89
2.76
it's not going to change the value of props.todo.checked.
5,157.65
4.49
And so we're going to actually have to write some logic in order
5,162.14
3.127
to handle that.
5,165.267
0.938
And so now let's create a new method, called toggle to do.
5,170.9
4.59
We're obviously going to need to take an argument here, because we
5,175.49
3.33
need to know which to do to toggle.
5,178.82
3.69
And so what are we going to do here--
5,182.51
2.92
so again, we're going to do this.setState and we can to dos.
5,185.43
7.04
It's this.state.todos.map.
5,192.47
2.12
So if you remember back a few lectures ago, when we talked about filter, map,
5,207.8
5.56
and reduce, we talked about how map applies a function to each
5,213.36
5.67
of the values in an array and will return
5,219.03
3.9
a new array with those values swapped out
5,222.93
3.6
with whatever this function returns.
5,226.53
2.4
And so how might we use that map function to handle the toggling of a
5,228.93
5.04
to do?
5,233.97
2.64
Well, first, which to do do we actually care about?
5,236.61
4.71
We only care about the to do with an ID that
5,241.32
4.166
matches the ID that were passed, right?
5,245.486
1.624
So we can immediately off the bat say, if to do
5,247.11
3.81
dot ID is not equal to the ID that were passed, what should we do?
5,250.92
7.02
AUDIENCE: [INAUDIBLE]
5,257.94
1.44
JORDAN HAYASHI: Yeah, we shouldn't do anything, right?
5,259.38
2.25
We should just return that to do.
5,261.63
1.65
OK, great.
5,266.02
0.5
We have one condition, but what happens with the to do that we want replaced?
5,266.52
4.767
We should flip its checked value, right?
5,275.4
3.35
And so we're going to want to return a new object,
5,278.75
4.76
and what should those objects' field be?
5,283.51
1.7
Well, we can say, ID is to do dot ID.
5,285.21
5.94
We can do text is to do dot text.
5,294.79
4.25
And what do we want the checked value to be?
5,299.04
2.11
AUDIENCE: [INAUDIBLE]
5,304.15
1.055
JORDAN HAYASHI: Yeah, the opposite of what it was before.
5,305.205
2.375
And now it looks like we should have something that works.
5,313.4
2.93
The problem is it doesn't.
5,319.217
1.083
It still doesn't change anything when we click this value.
5,323.68
4.45
Anybody have any ideas why not?
5,328.13
2.97
It looks like our toggle to do function should work.
5,331.1
3.9
We're setting state, we're updating the to dos,
5,335
2.829
we're mapping over this with this function,
5,337.829
1.791
where if the to do's ID doesn't match, we don't change it.
5,339.62
2.62
But if it does, we flip the to check value.
5,342.24
2.85
But when we click over here, nothing actually happens.
5,345.09
3.47
Why might that be?
5,348.56
1.238
Yeah?
5,349.798
0.5
AUDIENCE: [INAUDIBLE]
5,350.298
10.187
JORDAN HAYASHI: Yeah.
5,360.485
0.875
Exactly.
5,361.36
0.5
We defined this function, but we're not actually calling it anywhere.
5,361.86
3.34
And so just like we have this onDelete that passes a new onDelete
5,365.2
3.36
function to every single to do, we should also
5,368.56
2.37
have this thing called onCheck or onToggle that
5,370.93
5.91
passes the unique function to each to do that we
5,376.84
2.82
should invoke when we toggle it.
5,379.66
1.56
And so let's have an arrow function here so we don't
5,381.22
3.6
have to worry about the this binding.
5,384.82
2.73
And when on toggle's invoked, we should do this.toggleTodo with the todos.id.
5,387.55
5.43
And so now since we're passing a new prop here,
5,397.822
1.958
we should probably invoke that prop at some point.
5,399.78
2.083
And so where are we going to do it?
5,404.202
1.458
Well, we can do it in the input.
5,405.66
2.77
We can do something like onChange = props.onToggle.
5,408.43
5.99
And how do I know that this on change attribute exists?
5,418.44
2.44
Well, you can read the docs and it'll be there.
5,420.88
2.06
Or you can wait till the next lecture, when
5,422.94
1.95
we talk about event handling in React.
5,424.89
2.19
And so now we can create a to do.
5,427.08
3.24
And when we click it, look at that-- it works.
5,430.32
3.22
Cool.
5,436.635
0.5
So now we're tracking every single to do, whether it's checked or not.
5,437.135
4.28
But that wasn't really the goal, right?
5,441.415
1.625
The underlying goal was to keep track of how many to dos there were,
5,443.04
2.833
and how many unchecked to dos there are.
5,445.873
2.277
And so how might we do that?
5,448.15
1.88
Well, first let's create some divs.
5,453.79
1.816
This div says to do count.
5,460.7
4.41
And then we're going to have some JavaScript in line there,
5,467.72
3.57
and then maybe a div for unchecked to do count.
5,471.29
6.99
And again, some JavaScript.
5,478.28
3.535
Cool.
5,481.815
0.5
And so what is a quick and easy way to calculate how many to dos we have?
5,482.315
5.265
We're tracking all of our to dos in memory.
5,492.39
2.14
What are we using to track them?
5,494.53
2.23
Yeah?
5,496.76
0.5
AUDIENCE: [INAUDIBLE]
5,497.26
1.715