sannajammeh / trpc-swr

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

Conditional fetching #10

Closed veax closed 2 years ago

veax commented 2 years ago

Hello, thank you for a library, I'm actually struggling to find a way to call trpc useSwr hook conditionnaly. Based on the docs, with useSwr, we could do something like: const { data } = useSWR(shouldFetch ? '/api/data' : null, fetcher) But I don't see any examples with trpc.useSwr and I have typescript errors than I use the syntax like: trpc.useSWR(shouldFetch ? ['api.data'] : null) Type 'null' is not assignable to type ... which is expected type error as null is not a part of AppRouter procedures

Is there a way to do it? Am I doing something wrong? Thanks in advance

sachinraja commented 2 years ago

Thanks for bringing this to my attention! I'll fix the types later today and do a release.

sachinraja commented 2 years ago

released in 0.1.3