text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
So now we have a way of
recognizing which to do is which. | 4,704.12 | 3.23 |
And so say we wanted to get rid of one,
it's now pretty easy to do that, right? | 4,707.35 | 6.3 |
So if we want to now remove to
do, that should now do what? | 4,713.65 | 11.92 |
Does it make sense to have a
remove to do with no arguments? | 4,725.57 | 4.341 |
Not really, right? | 4,729.911 | 0.749 |
Because we need to know exactly
which to do we want to delete. | 4,730.66 | 2.583 |
It makes sense that we want to
add a to do with no arguments, | 4,733.243 | 3.297 |
because there's no particular
to do that we want to add. | 4,736.54 | 2.37 |
We create that text later. | 4,738.91 | 1.959 |
But when we want to
remove a to do, we need | 4,740.869 | 1.791 |
to know exactly which to do to remove. | 4,742.66 | 1.75 |
And so now we should have remove
to do actually taking argument. | 4,744.41 | 4.741 |
And so what argument should it take? | 4,749.151 | 1.499 |
Well, we created some sort
of unique identifier field, | 4,750.65 | 3.02 |
so we can just take the ID. | 4,753.67 | 3.32 |
And so now how are we
going to remove the to do? | 4,756.99 | 3.78 |
Well, we could do this.setState, which
is the only way to update the state. | 4,760.77 | 5.8 |
And the to dos are what? | 4,766.57 | 3.87 |
They can take the old state's to dos
and just filter them, where for each | 4,770.44 | 7.72 |
to do, what do we want to keep? | 4,778.16 | 5.71 |
Well, as long as the to do dot ID is
not equal to the ID that we pass in, | 4,783.87 | 6.71 |
those are the to dos
that we want to take. | 4,790.58 | 2.81 |
Great. | 4,796.27 | 0.96 |
But the Delete button is not working. | 4,797.23 | 3.87 |
Why not? | 4,801.1 | 1.17 |
Well, our component called
to do is not doing anything | 4,802.27 | 6.18 |
when you click on the button. | 4,808.45 | 4.03 |
So how might we handle that? | 4,812.48 | 1.4 |
Well, that's where props come in. | 4,816.336 | 1.374 |
Since we can pass any
JavaScript value as props, | 4,817.71 | 3.84 |
what's to stop us from just
passing a function down? | 4,821.55 | 2.85 |
And so when we map over
the to dos like this, | 4,824.4 | 4.004 |
we can actually also
pass a function down. | 4,828.404 | 8.656 |
So we could pass something called
onDelete and just pass a function. | 4,837.06 | 6.31 |
And what would that function do? | 4,843.37 | 2.65 |
Well, it's going to call
this.delete removeTodo. | 4,846.02 | 4.68 |
And what are we going to
pass in when we invoke that? | 4,850.7 | 2.962 |
Well, this todo.id. | 4,853.662 | 0.808 |
Does that make sense? | 4,871.516 | 0.874 |
So we're mapping over to dos,
and for each to do in that array, | 4,875.06 | 3.69 |
we're going to invoke that to
do function, that component. | 4,878.75 | 4.89 |
And what are we passing as props? | 4,883.64 | 1.8 |
We're passing it this
thing called onDelete | 4,885.44 | 2.67 |
which is a function that invokes
remove to do with that to do's ID. | 4,888.11 | 4.19 |
So for each to do that
we create, we're passing | 4,892.3 | 2.74 |
a unique function that
removes that particular to dos | 4,895.04 | 4.07 |
from our global state. | 4,899.11 | 2.547 |
And of course, we're also
passing down the to dos, | 4,901.657 | 2.083 |
so it knows exactly
which text to render. | 4,903.74 | 4.73 |
And so how do we get that to fire
when we click the delete button? | 4,908.47 | 3.994 |
Well, that function's
just a prop, right? | 4,921.18 | 3.03 |
So when we click that
button, what should we do? | 4,924.21 | 4.02 |
Well, we should invoke
props dot on delete. | 4,928.23 | 2.67 |
And so now when we add things,
if we click that button, | 4,936.38 | 10.82 |
the correct one is deleted. | 4,947.2 | 3.12 |
Again, how does it know that that first
one is the one that should be deleted? | 4,950.32 | 4.11 |
Well, it's because each
to do that gets rendered, | 4,954.43 | 2.28 |
so when we map over the to dos in
our state, we pass a unique on delete | 4,956.71 | 4.17 |
handler down. | 4,960.88 | 2.1 |
It's a function that gets bound to
that particular to do's ID field. | 4,962.98 | 5.14 |
And so when we click that
particular to do's delete button, | 4,968.12 | 3.68 |
it invokes remove to do with
that ID, and so it knows | 4,971.8 | 2.52 |
to filter based on that particular ID. | 4,974.32 | 5.408 |
Does that make sense to people? | 4,979.728 | 1.984 |
Great. | 4,989.421 | 0.499 |
So we've handled the two big parts-- | 4,989.92 | 3.51 |
well, the add and the delete
part of the assignment. | 4,993.43 | 3.34 |
And so what are we missing? | 4,996.77 | 1.34 |
We're missing some way of tracking
how many to dos we have total | 4,998.11 | 3.612 |
and how many to dos that we still
have to complete-- or in other words, | 5,001.722 | 2.958 |
to dos that are unchecked. | 5,004.68 | 2.91 |
And so now we have a choice--
how are we going to handle this? | 5,007.59 | 2.83 |
Well, if we were back in
Vanilla JavaScript world, | 5,010.42 | 3.047 |
a way to do that would
just be to keep track | 5,013.467 | 1.833 |
of however many unchecked there are,
keep track of however many total | 5,015.3 | 3.21 |
there are. | 5,018.51 | 0.99 |
And just mess with those values every
single time we add, delete, or check | 5,019.5 | 5.22 |
or uncheck a to do. | 5,024.72 | 2.41 |
But in React land, that seems a
little imperative for our like, | 5,027.13 | 3.18 |
and so there might be a more
declarative way to do this. | 5,030.31 | 3.84 |
But in order to do that, we also
need to track every single to do, | 5,034.15 | 3.59 |
whether it's checked or not. | 5,037.74 | 1.9 |
And so currently our to dos are
an ID field and a text field. | 5,039.64 | 7.34 |
But maybe it would be better to also add
a field of whether it's checked or not. | 5,046.98 | 3.63 |
And so now when we add to dos, we
add an object with three keys-- | 5,054.52 | 3.18 |
an ID which is guaranteed to be
unique, because we're incrementing | 5,057.7 | 2.97 |
this ID counter, which lives outside of
our app; the texts that we prompt for; | 5,060.67 | 5.17 |
and lastly, a value called checked,
which keeps track of whether that to do | 5,065.84 | 4.04 |
is checked or not. | 5,069.88 | 2.04 |
And we should just
initialize it with false, | 5,071.92 | 1.95 |
because there's no point
in creating a to do. | 5,073.87 | 2.102 |
That's already done. | 5,075.972 | 3.569 |
Cool. | 5,079.541 | 0.499 |
And so now we're still
missing one thing. | 5,080.04 | 6.73 |
So when we create to dos, we
just create an empty checkbox. | 5,086.77 | 4.97 |
And so no matter what,
it's going to be unchecked. | 5,091.74 | 2.52 |
And so we should set that check field
to equal whether that particular to do | 5,094.26 | 5.55 |
is checked or not. | 5,099.81 | 0.83 |
And so how might we do that? | 5,100.64 | 1.29 |
Well, with props.todo.checked. | 5,101.93 | 1.62 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.