如何在rtkquery中构成错误,以及如何将它们结合在自定义钩中
如果我有一个React视图,该视图需要通过RTKQuery Cache/API调用进行两个查询,则如何将isloading
,error
等组合组合?
操作
我已经想过要做以下
const useUsersAndHousesQueries = () => {
const users = useUsersQuery()
const houses = useHousesQuery()
const isLoading: boolean = users.isLoading || houses.isLoading
const isError: boolean = users.isError || houses.isError
// ...users || ...houses boolean values
const data = {users: users.data, houses: houses.data}
const error = {...} // How are RTKQuery's errors structured? Or do I structure them myself? Is it derived from the api call's response? I want to combine them so they can be rendered in an alert together in a component as a warning
return {isLoading, isError, data, error, ...}
}
If I have a react view that requires two queries to be made from an RTKQuery cache/api calls, how can I combine the isLoading
, error
, etc?
I've thought of doing the following but I'm not sure how the error objects are composed
Could possibly write a special hook that does just this
const useUsersAndHousesQueries = () => {
const users = useUsersQuery()
const houses = useHousesQuery()
const isLoading: boolean = users.isLoading || houses.isLoading
const isError: boolean = users.isError || houses.isError
// ...users || ...houses boolean values
const data = {users: users.data, houses: houses.data}
const error = {...} // How are RTKQuery's errors structured? Or do I structure them myself? Is it derived from the api call's response? I want to combine them so they can be rendered in an alert together in a component as a warning
return {isLoading, isError, data, error, ...}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
fetchbasequery
,则是fetchBaseQueryError
或(在非常意外的情况下) ,<代码>数据将是服务器的响应(如果以某种形式使用)
If you are using
fetchBaseQuery
, it is eitherFetchBaseQueryError
or (in very unexpected cases) aSerializedError
:In the case of a
FetchBaseQueryError
,data
will be the response from the server (if available in some form)