I use the redux toolkit to create an API The question is short: how to dynamically change the baseUrl in the API? The question in detail: Here is the createApi method An object is passed to this method, one of the keys of which is "baseQuery"
export const WebApi = createApi({
reducerPath: 'API',
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:3001/api' }),
endpoints: () => ({}),
});
And here's the question, how do I dynamically change the baseUrl? It is in the store, but I can't just put it here. I tried the solution from the customization query documentation https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#constructing-a-dynamic-base-url-using-redux-state
But it does not allow to change exactly the baseUrl, only dynamically process the request itself, which already comes AFTER the baseUrl
So, how can I get and change baseUrl in the createApi method?
url
, apparently theurl
only stops at what thedynamicBaseQuery
returns, but does not extend the endpoint's url, for example, expected should behttp://sample-url/verson1/data?anyparam=true
.version1
is the dynamic var that comes from a request from the backend, but the actualurl
turns out to behttp://sample-url/version1/
, have you had similar issue before working with dynamic base query? – Replay