英文:
Is it possible to define RTK Query queries without QueryArgs?
问题
在RTK Query中,对于一个查询的定义是 query<ResultType, QueryArg>
。对于那些不需要向API发送任何内容的端点(例如getAllX),你可以在模板中传递什么作为QueryArg呢?它不接受只有一个参数的情况。
到目前为止,我使用了诸如 undefined
和 null
这样的类型来表示不需要发送任何内容,但当你使用钩子时看起来不太美观:const {...} = useGetXQuery(undefined)
,我相信一定有更好的方法,但是在互联网上搜索没有找到相关结果。
英文:
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.
答案1
得分: 6
已解决,您需要将void
用作类型,然后可以像这样使用该钩子:const {...} = useGetXQuery()
。
英文:
Figured it out, you need to use void
as a type, then you can use the hook like this: const {...} = useGetXQuery()
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论