-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to add extra arguments when using custom query #1335
Comments
I face the same issue I think it could be nice to retrieve what we injected at this level const customBaseQuery = (
args,
{ signal, dispatch, getState, extraArgs },
extraOptions
) => {
} |
You can pass in things there by making it part of the Wanting to pass things in there and not making it part of You have an escape hatch to store stuff into state and access that from the |
Thanks for your quick reply and all of theses informations @phryneas But even if it's a class that I've put in the extraArgs of redux thunk, does this still must be pass as args ? The only way I currently see to retrieve it without having to pass them as args is by using the return of a dispatch const customBaseQuery = (
args,
{ signal, dispatch, getState },
extraOptions
) => {
const myClassInstance = await dispatch(({extraArgs}) => extraArgs.myClassInstanceThatWasInjected)
} This might be a bad practice or seems to be really hacky no ? |
That is perfectly reasonable, although I think you might be able to directly access |
I ended up trying this because this parameters was not mention in the docs https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#basequery-function-arguments |
This seems fixed by #1378 I just need to update this library Maybe we can add the info with #1649 To clarify the situation we can get the extraArgs with const customBaseQuery = (
args,
{ signal, dispatch, getState, extra },
extraOptions
) => {
const myClassInstance = extra.myClassInstanceThatWasInjected
} |
So should this be closed? |
I think so, yeah. Thanks! |
I've been playing with RTK Query for a few days and I don't know if I'm missing something or just missunderstood the concept. In my project Im using custom query. I would like to have a possibility to pass extra arguments from place where my hook is being used. I think it would be great to have something like this:
And then when using hook created by
createSlice
:or
I would like to decide about my flag value in a place where Im using my hook.
I know I can just add it as another field in
myArgs
object but then Ill need to type it in every place wherebuild.mutation/build.query
is used.The text was updated successfully, but these errors were encountered: