call db directly in next js app router
hey guys im following josh saas tutorial for some insight in this new version of nextjs, and the i came accros this im feeling somewhat uncomfortable about this because before this im using t3 but still in page router and obviously i always use the trpc first to fetch data, my question is will this pattern is safe and will be common in future?
thanks!
12 Replies
Well for fetching dynamic routes it is great but if you wanna use trpc you can also do that in server components you just have to create a trpc client for that.
any example you can refer me to for call trpc in server components?
https://github.com/anonymous-sherlock/crm-software/blob/main/src/app/_trpc/serverClient.ts
check out this repo of mine
GitHub
crm-software/src/app/_trpc/serverClient.ts at main · anonymous-sher...
Contribute to anonymous-sherlock/crm-software development by creating an account on GitHub.
thankss!!
if you have any doubt dm me
ooo i see it allow us to use the trpc from rsc right?
so is there any pros and cons using this pattern
when to use and when to not use it?
if i want to use the example you gave me do i need to change this
no you don't have to change it here this is only for client side trpc call server side call won't need
i see
so we can have many option rn now right?
many options for? didn't understand.
many options to fetch the data
since we got the new rsc stuff
https://github.com/anonymous-sherlock/crm-software/tree/main/src/app/_trpc
if you check there are two file one for client.ts which using trpc/reactquery to run on client
and another file name serverClient.ts which using batch link to make all call rpc so it won't run on client.
GitHub
crm-software/src/app/_trpc at main · anonymous-sherlock/crm-software
Contribute to anonymous-sherlock/crm-software development by creating an account on GitHub.