Skip to content

RTK Query: Correct Store Configuration for Code Splitting? #2506

Answered by markerikson
kekoawong asked this question in Q&A

You must be logged in to vote

Per our docs, there should only be one "API slice" in the app (ie, a single call to createApi).

Note that when you do something like const usersApi = emptySplitApi.injectEndpoints(), it actually returns the same api object reference - injecting the endpoints mutates that API object. That means that there won't be, say, a usersApi.reducer, because there really is no usersApi object - just emptySplitApi, which will later have the users-related endpoints added to it.

So, for the store setup, you add the one API cache reducer and one API middleware to the store, and that's all you need to do.

Replies: 4 comments 2 replies

You must be logged in to vote
1 reply
@kekoawong

Answer selected by kekoawong

You must be logged in to vote
0 replies

You must be logged in to vote
1 reply
@nrl240

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants