How can I get response in data ref when using vue-query with fetch #1535
-
I can see, that generated code for fetch and vue-query wraps response in an object with http status:
This results in data ref having this as a value. But I am not interested in status - how can I make it so that data contains the response only, so that I don't have to do this for every query:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
cc @soartec-lab |
Beta Was this translation helpful? Give feedback.
-
That's not possible at the moment. Status code must be issued every time. |
Beta Was this translation helpful? Give feedback.
-
Look i am going to help you first create a custom wrapper for that export async function fetchWrapper(url, options) {
const res = await fetch(url, {
...options,
method: options.method || 'GET',
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.message || 'Error fetching data');
}
return data; // Only return the data
} After that call it like that export function useCustomQuery(queryKey, apiUrl, options = {}) {
return useQuery(queryKey, () => fetchWrapper(apiUrl, options));
} use it in ur component const { data, error, isLoading, isError } = useCustomQuery(
'exampleQuery',
'ur url'
);
return { data, error, isLoading, isError }; |
Beta Was this translation helpful? Give feedback.
-
Hey everyone. I fixed this issue by i added new config option. Please try this 🙌 https://orval.dev/guides/fetch-client#return-original-defined-return-type |
Beta Was this translation helpful? Give feedback.
Hey everyone. I fixed this issue by i added new config option. Please try this 🙌
https://orval.dev/guides/fetch-client#return-original-defined-return-type