sannajammeh / trpc-swr

tRPC-ified SWR hooks
https://trpc-swr.vercel.app
MIT License
210 stars 5 forks source link

Skip global instance of `createTRPCClient` #2

Closed KATT closed 2 years ago

KATT commented 2 years ago

The readme currently tells you to create a global tRPC client instance.

This will be problematic when SSRing because the same TRPCClient will be used for all requests.

Instead, create the client in a useState(() => ... callback

Related:

sachinraja commented 2 years ago

I did see that in the docs but was unsure of the reason.

This will be problematic when SSRing because the same TRPCClient will be used for all requests.

Could you elaborate on why this is problematic? Also note that this package doesn't do any special SSR logic like @trpc/react does. The only SSR you'll get with this package is through server side suspense.

KATT commented 2 years ago

Examples:

sachinraja commented 2 years ago

Ah ok that makes sense. I'll fix the readme.