Creating a Wrapper hook over useQuery in Typescript
Hey I’m trying to implement something like this
const { useQuery } = require("react-query");
const useAuthedQuery = (...options) => {
const query = useQuery(...options);
if (query?.error?.response?.status === 401) {
// Insert custom access-token refresh logic here. For now, we are
// just refreshing the page here, so as to redirect them to the
// login page since their token is now expired.
window.location.reload();
}
return query;
}
export default useAuthedQuery;
But the code for the frontend is in typescript and I’m not able to figure out how to setup the types for input and output for the same properly please do let me know how can I tackle this thanks
My use case is to handle 401 errors and refresh etc the page accordingly
const { useQuery } = require("react-query");
const useAuthedQuery = (...options) => {
const query = useQuery(...options);
if (query?.error?.response?.status === 401) {
// Insert custom access-token refresh logic here. For now, we are
// just refreshing the page here, so as to redirect them to the
// login page since their token is now expired.
window.location.reload();
}
return query;
}
export default useAuthedQuery;
But the code for the frontend is in typescript and I’m not able to figure out how to setup the types for input and output for the same properly please do let me know how can I tackle this thanks
My use case is to handle 401 errors and refresh etc the page accordingly