Search code examples
reactjstypescriptreduxredux-toolkitrtk-query

Is it possible to define RTK Query queries without QueryArgs?


The definition for a query in RTK Query is query<ResultType, QueryArg>. All of this is fine for queries where I actually need to send parameters to the API. However, I have some endpoints which don't require anything to be sent (something like getAllX). What can I pass as QueryArg here in the template? It won't accept having one argument.

So far I've used types like undefined and null to denote that nothing needs to be sent, but it looks ugly when you use the hook: const {...} = useGetXQuery(undefined), and I'm pretty sure there has to be a better way, but scouring the internet yielded no results.


Solution

  • Figured it out, you need to use void as a type, then you can use the hook like this: const {...} = useGetXQuery().