In this way, we are able to use TRPC in the client part. So, here is our slash index, okay, the own page of our application. We can use TRPC like this, TRPC dot author dot list, but if I remove this list and I press control space, as you can see with TypeScript, we are able to know that I can call the add, delete, and list. And this is so cool because we didn't generate any kind of types to do that, is all of things out of the box.
Okay, so I, okay, great, so as you can see here, we are looking for the authors. Then we manage the handle delete and handle save, and every time I save and delete, I invalidate the list to refresh the list. So we can start our application. Here there are some Prisma codes. Okay. And if we go here, we have this list, and with the save button we save a new author, and then we can delete them. Great. One really cool thing is that if you go into the routers, in the author router, great, and we decide to change the name of the procedure, so let's change this one, we can rename the Add to new, and boom, into the index here, you can see that TypeScript renamed it for me, so it's really great things. But if we decide to, don't do with the renamed symbol, but do it manually, so I remove here head, okay, if we do it manually, like this one, as soon as I move myself into the index, we can see that TypeScript is notify me that something changed under the hood. So it's a really great benefit to interact from your server and client part, and I think this is so cool.
But I want to show you more. Now we are going deep into the library, because I want to show you how it works under the hood. So let me refactor my class. Here, add new, remove, save. So I think now it's okay. So if I go here. Yeah, perfect. If I open the inspect, I place the few breakpoints into the client library of TRPC. Okay, so if I click on this one, great. And I refresh. As you can see here, we are defining, we are into the TRPC client. Maybe you can't see. Maybe yes. Okay, we are inside of the TRPC client, and we are defining the methods. So, query is a get, mutation is a post, of course, because a mutation needs to have some information extra. Okay, if we go on, we did debugger, and we enable this to debug.
Comments