zustand + next trpc/client. With slightly more complex feature. Vanilla client?

The problem i'm having is that trpc are hooks and not async functions that i can call in my zustand slice. And handle the logic in one place to keep thing less convoluted. My feature is tracking crud operations on lists and items in a list. Tracking which item and list is selected. And voiding the top level get call for this data to make sure the data is up to date. As other users can have access to shared lists. I see useContext, that changes it into a async function with the added fetch method. Should I use the vanilla client for this?
4 Replies
Max
MaxOP15mo ago
perhaps instead of voiding my get call when I do crud operations I'll just call get after the crud operation and set the state there.
Yiannis
Yiannis15mo ago
Maybe try importing the app router and use it as a caller. https://trpc.io/docs/server/server-side-calls The hooks you mentioned are part of tanstack query and are meant for react/front end, where as it sounds like you need to do server calls.
Server Side Calls | tRPC
You may need to call your procedure(s) directly from the same server they're hosted in, router.createCaller() can be used to achieve this.
Yiannis
Yiannis15mo ago
If you are using t3 you can export the createInnerContext function so the caller can have the same context as your api calls It lives inside the trpc file in the server folder
Max
MaxOP15mo ago
@yiannis_ yeah need todo it client side. I just ended up using useContext so I can use the fetch method for my getLists in the onSuccess method of my mutations and handled maintaining my zustand state with different actions. So CRUD mutation on list or item, getList, handle Zudtand state. Now I can maintain which list and item is selected, keep my data up to date, and keep the code clear.
Want results from more Discord servers?
Add your server