OK, let's move on to delete cell, which should be really easy now that we're using the library to
remember delete so we can go and take a look at the action that we're going to receive in that particular
case.
So instead of my actions index thoughts file, here's a definition for delete cell action.
So we're going to get a of property that is a string.
And we had said very briefly that this payload was going to be the idea, the cell that we want to delete.
We're going to try to find a cell with that particular ID and somehow delete it.
Now, remember something that we discussed very briefly in the last video inside of our state being
managed by this reducer.
We've actually got two locations where this ID is going to be used and we need to make sure we remove
that ID from both locations.
So we have to go through the order array, which is going to be a array of strings, all the different
IDs of our different cells.
We need to find the appropriate ID and remove it.
We also have to go through data.
We have to find the appropriate cell inside there and delete that as well.
Because we are making use of the IMR library, doing these updates is going to be pretty straightforward.
I really recommend that you keep open that documentation page I just showed you the one that says update
patterns.
And this will tell you exactly how to do a variety of different updates to either objects or to arrays.
In this case, we want to update an object and we want to update an array so we can very easily just
take a look at the documentation and will tell us how to make these different updates.
So first, in order to delete the cell out of our data object, we can do something like this right
here.
We're just going to call delete, look at our state object.
And we're going to remove whatever that key is, so in this case, it's going to be our action Palit
property.
Let's take care of that first instead of delete cell, I'm no longer going to return state just because
we do not have to.
And we'll do a delete state that data.
Action, not payload.
And that's it.
Then next up.
We can go down to Arae mutation's and this will tell us how we can delete an element out of this array,
notice that there is documentation here for delete by index.
We don't actually know the index of this particular ID right now, so we're not going to use the Leapai
index.
Let's keep going down.
And you will notice down here, they've got pretty much our exact use case, so we've got Dileep by
IDX.
We've got index, so they're going to find the index of the appropriate record that we want to delete
and they call Splice to remove it.
So we can do pretty much exactly that.
We can't technically also do a filter operation as well, which in my opinion is just a little bit easier.
So we're going to use the filter case just because it doesn't require these two separate lines of code.
Let me show you how we would achieve this if we were using filter.
So if you're going to do a filter, we could do state court order.
I'll then do a state court order filter.
We're going to take a look at each ID.
And we want to return calls on the ID that we do not want to keep, so I'm going to do ID not equal
to action that payload.
Now we're going to create a brand new.
Order and assign it back to state court order.
And that's pretty much it.
Now, we've handled delete cell and just two very small lines of code.
OK, let's take a pause right here, now that we've handled this case, move on to our other two cases
in just a moment.