And the last piece of functionality I'd want to add is the ability to edit the item, probably the hardest
one, because they're just going to be a few moving pieces, but I think we're going to be in good shape.
So let's start working on it.
We're going to go with objets.
And then I would want to come up with my function.
So let's scroll up removing them.
And then right after the remove item, we're going to go with const added item.
And again, we're going to be looking for Deery just like we remove them.
In this case, what I would want is to get that specific item whose idea matches.
So in here I did not return that item.
I only returned items whose D did not match.
In this case I do want to get that item and I'm just going to use a variable here specific and that
is equal to a list.
So my state value and I'll use my find method can wait right over.
And I say if the item.
ID matches Van, please return that item and then once I have my item, I would want to go with set
is everything.
I'll set it equal to true then as far as the ID remember that set, etc..
I'm going to go set at it.
It is equal to the ID that I'm passing in right here.
And then the last thing if I'm editing, I also don't display it.
Well, which item I'm actually editing.
So I would want to grab that title value and pass it in to my name.
So what I'm gonna do is set nine and then I'm going to go with a specific item which of course holds
that value, and then I'll pass in the title.
So that should do it.
And of course, we can pass it down to our last same spiel.
We're going to call this at a time.
Just like with the removal, we're going to go with added item is equal to the added and that item function,
OK, so we save it and in the list I would want to structure it.
So we're going to go with edit added item work show and then of course we have our button already.
So we go on click not on is equal to the edit item, but I need to pass in my one function added item
and then I pass in my head, I save it and then of course we'll have to handle that when we're submitting
the form.
So let me add first item and of course once I click, check it out.
I have here to add it.
So I clearly state that we're editing online, which I'm actually editing.
So now of course, we just need to deal with that when we're submitting the form.
So let me scroll up.
Remember, we have that else.
If so, if there's some value, then we're editing.
And the reason for that is because I don't want to edit item with an empty value.
So I don't want to do something like this.
I don't want to change this to an empty rack.
That's why we had that flag over there.
But we just need to add a little bit more functionality.
And in fact, it's going to be somewhat simple where we're going to go with our list.
And again, just the practice will right away pass it into our setlist, so I'm going to be setting
list to a new value and I'm going to be mapping over my current list because I know that I will always
return a new correct.
And in here, I'm going to say that I'm going to be accessing the item from my list.
And then if the item ID will match Eridani, well, then I'll do something.
If not, then I'll just return the item.
So by default, I'll always return the item.
Or there's also going to be a flag here where I'm going to say if item if item ID matches the added
ID.
So my state value, the one that I'm setting up when I'm adding the item.
Remember, we got our specific item and then we set the state value here.
If that is the case, well then I would want to return.
I'll copy all the values from the item over here.
So say item, but I'll change the title so it will stay the same.
I'm not going to change it, but title now will be equal to the name Mike.
So again, we have our set list.
We're iterating over our list.
That's why right away passerelle because I know it's going to be a new array at the end of the year
anyway.
I have my item.
If the item ID matches whatever I have in state, then return all the properties.
And more specifically, I'm just looking for the ID and then change the title to whatever is the state
value right now.
Because remember when we set up ticket item, also change the state value for the name.
OK, good.
And then once we have changed the list, that is just a few things that we would want to add and that
one is set name to be empty value.
Then I also would want to set back set edit it now.
So set edit id and I'll set it equal to and now then also set is editing and I'll set it equal to force.
OK, so again this one goes back to normal, this one goes back false because I don't want to keep those
values true and whatever was there.
And then lastly we can just call the show alert and yes I would want to show.
So I'll pass passing the value of true that it's going to be a success and will say value changed value
and then changed.
We'll save this one and we can test it out on a bigger screen because that way you can also see the
value your share.
So I go with first item.
I had it there it is now in my state.
You can see that array has some value and I can also see that my alert was displayed and then of course
it went away.
Then I can have my second item over here, notice how I'm typing, can I submit?
And now the moment I'll click on edit, check it out how this state of ours will change.
So once I click, I have one for Daddy and then I have one for the second time.
So now of course this is my name.
OK, and then of course for editing this one also is true.
So if we tried to submit with no values, we won't be able to do that.
Click and we have please enter value.
So that's not going to work.
But I can just go back to, I don't know, random value.
And then once I click, the second item has been changed to a random value, hopefully medicines and
now we can just deal with our local storage.