javascriptrtk-query

Using RTK Query with a store that contains parent keys


I work for a large company that has an in-house framework that's built in React. We import the framework and build our application on top of it. They generate the Redux store on their end, and combine reducers that we send them in a specific file. Once the store is generated, it looks like:

{
  stuff: {
    myReducer: {}
  },
  moreStuff: {},
  theirStuff: {}
}

I was trying to use RTK Query for an API we are building, but it's putting the reducer for the query under the 'stuff' key, and this is causing the query to persist in the pending state. After all my testing, it seems that RTK Query doesn't work when the reducers are a child in the store? Is there an option to handle this?

I commented everything out and created store locally in our code, and the queries worked just fine. Unfortunately, in order to use their components, we have to use their generated store.


Solution

  • No, that's not possible with normal means.
    RTK Query is meant to have a slice at the root of the store. You'll have to convince that other team to mount it at the root.

    Source: I'm the author of RTK Query.