Following is my implementation of the useLazyQuery hook:
const [trigger,
{
loading: prodLoading,
error: prodError,
data: prodData
}
] = prodApi.endpoints.getAllProducts.useLazyQuery();
where the result
parameter is de-structured into prodLoading
, prodError
, prodData
respectively.
When the right parameters are passed to the query, the fetched products can be accessed through the prodData
, but on error nothing is accessed through prodError
, which brings me to my question, how do we handle errors in the useLazyQuery
hook?
Is there any way to get parameters like isLoading
, error
we use in the useQuery hook?
const {data, error, isLoading, isSuccess} = useGetAllProductsQuery('', {skip,});
trigger
? – Apps