Right, and before that, let's set this loading to true. And then let's await. Okay, now I need to copy the code. All right, so I will copy from line 47 to 51. 58, and then paste it here. And then, so this is the raw data. I will replace it with my data here, which is the updated row. All right, so you can learn more about fetch API later, but this is how you call the fetch. If you want to send the post method to your backend. All right, and then, when this is done, now let's set is loading to false. Okay, now let's save this, and then let's try to create new row. All right, if I press Enter, okay, now it's create data to the backend. Now, to verify that it works, I will fetch the data from the backend and using fetch in the browser here. Okay, cool, so here, this is the new data here that we just created. So it works. All right, so next, let's, okay, sorry, before we move to the edit part, I want to show you how we can handle the error as well, because this happen all the time. So for example, if the user missed some field and then they press Enter, and that data sent to the server, and then the server reject with the error, and so how do we handle that error? So for this case, I will fake the data here. Let's say that I forced the manufacture date to null. Okay, so I do this because I want the server to throw errors, because right now, you have to provide all the fields to the backend. So to simulate the error, you can put a null inside manufacturer dates. All right, so if I save here, and then I try to create a new row, right, and then I press Enter. Now. Now this is a, the server will troll the error here, right? But we don't see anything on the frontend because we haven't handled the error yet. And to handle the error with fetch API, we need to get the response. IfResponse, and then we have to check if, ifResponse is okay or not. All right. So, let's just do the, the error part. IfResponse is not okay, meaning that if it's not 200, say 200 x, x datas, then it means that something is wrong. And what we can do here is to troll that error inside this process row update. Okay, and then I'll show you later why we need to troll it. Okay, so let's troll, let's troll, maybe I have to do this first. I will get the error from the response. So respond.data. And then I will troll that error from this function. Now let's see what it looks like when I add new record to, alright, then I press Enter. Alright, so what I like about this is that if something is error inside this function, the user will not leave the Edit Mode. Which makes sense because whatever happens, if user leaves the Edit Mode, it means that the data that they just updated will lost. So this is a good experience. If something wrong, then it should show some warning and then let them update the data and then save it again, right? So, now we can do the same thing here. Next step is how you can handle that error because right now the data grid show an error that a call to process role update was not handled because this function is missing. So, we can use this and add it to the data grid and then it will give us the error and we can do anything with it. And in this case, I'm going to just alert the error. So, the error here is this one and usually the error contain a message property. So if I save the file and then I add a new record and then I submit. Okay, so now what happened here is that when this one sends back as not okay, we throw errors out of the processor update and then DataGrid lets us handle that error in this prop on process will update error and then we show the alert of that message to the user. So if I click okay here, the user will stay in edit mode and then let user change the data to something else. and because I had coded, it will always error every time. Cool okay, I will remove this one and set it back. Alright, so this is how you handle error with the process role update and on process row update, pretty useful. Okay, so next, it's pretty much the same.
Comments