Skip to content

RTK Query: circular type reference #2191

@jeron-diovis

Description

@jeron-diovis

I saw #1126 and #1518, they are both about async thunks, and probably can be solved with workaround about how reducer is exported (didn't try it myself).

I need AppState in RTQ endpoint definition, like this:

export const MyApi = createApi({
  baseQuery: ...,

  endpoints: builder => ({
    whatever: builder.query<..., void>({
      queryFn: (_, { getState }, opts, baseQuery) => {
        const state = getState() as AppState
        return baseQuery(`users/${state.user.id}/whatever`)
      },
    }),
  }),
})

I don't even have initial state to try this approach.
What can I do in this case, aside of casting state into any?

Obviously, in this simple example I can rethink my api and just pass user id as explicit parameter. But in general case, is it possible to solve?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions