RTK query based on data from another request


I have some rtk query, that query data based on response of another request ( with axios )

const { dat } = useGetDataQuery({
  keys // it comes from another request

export const someApi = createApi({
  reducerPath: 'someApi',
  endpoints: (builder) => ({
    getData: builder.query<
      { keys: string[] }
      query: (arg) => {
        const { keys } = arg
        return {
          url: '/some_endpoint',
          params: {

And in this case data from previous request it’s keys.
Is it possible make request inside query and use this data for my query, instead of doing
this request outside and pass data as params?

>Solution :

I wouldn’t recommend it. Theoretically it is possible, using queryFn, as you have access to getState there – but if that state value would ever change, that wouldn’t re-execute your query. It’s really best to just put in dynamic values as argument.

Leave a ReplyCancel reply