what would be the best way to refetch state that I got via getServerSideProps using TRPC?

Currently I'm passing in initial state from serverSideProps, just using prisma client to make the fetch. But then when a user makes a new post, I want to update the list of posts that the user sees. Issue is, I have nothing to refetch
8 Replies
Piotrek
Piotrek3y ago
You can return the dehydrated state itself (not the response) The you just use hooks as usual They fetch on server side tho But you have access to methods like refetch
Piotrek
Piotrek3y ago
SSG Helpers | tRPC
createProxySSGHelpers provides you a set of helper functions that you can use to prefetch queries on the server.
jack
jack3y ago
so i still write trpc call on server side?
Piotrek
Piotrek3y ago
Yes, but you don't use the response, just pass the state tRPC then uses it and does not call the API the second time So you have SSR but with access to the request hook on frontend Just like in the example I sent
jack
jack3y ago
aha that makes sense pretty cool stuff, thanks
Piotrek
Piotrek3y ago
No problem frecklebyte
jack
jack3y ago
so what do i have to pass to the Context in this case? in the example it takes no params, but the context ive imported requires a parameter; assuming it has something to do with the next context stuff?
Piotrek
Piotrek3y ago
If your API call depends on the context you have to pass it
Want results from more Discord servers?
Add your server