-
This might be a really stupid question, but how can I declare a timeout for query or mutation? I am coming from I wonder if there is a simpler way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hmm, by wrapping const baseBq = fetchBaseQuery(options);
const baseQuery = (
args: string | FetchArgs,
api: BaseQueryApi,
extraOptions: { timeout?: number }) => {
return Promise.race([
baseBq(args, api, extraOptions),
new Promise(resolve => setTimeout(() => resolve({ error: "timed out" }), extraOptions.timeout ?? 10000)
])
} |
Beta Was this translation helpful? Give feedback.
-
you can use this way if you would want to put timeout to an endpoint or to a basequery and when you apply it to the basequery, it is applied to all endpoints. if no timeout is applied anywhere, there will not be a default one. I hope this helps. export const api = createApi({ you can read more here https://redux-toolkit.js.org/rtk-query/api/fetchBaseQuery#adding-a-custom-timeout-to-requests |
Beta Was this translation helpful? Give feedback.
Hmm, by wrapping
fetchBaseQuery
: