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, ...}
}