Typing for RTK Query per sliced in workspaces projects #5179
Unanswered
lamhungypl
asked this question in
Q&A
Replies: 1 comment
-
|
@lamhungypl for typing dispatch and state from an injected api without importing the root store, use the generic types from redux-toolkit directly: import type { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit';
import { meQueryApi } from './me.queries';
// wide enough to accept any RTK Query thunk without the actual store type
type AppDispatch = ThunkDispatch<any, any, UnknownAction>;
// state shape that includes your api's cache slice
type ApiState = { [meQueryApi.reducerPath]: ReturnType<typeof meQueryApi.reducer> };
for dispatching queries from your utility functions: export const prefetchMe = (dispatch: AppDispatch) => {
dispatch(meQueryApi.endpoints.getMe.initiate());
};ref: RTK Query code splitting -- this pattern is exactly what |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context:
I'm working on an NX Pnpm workspace and following the RTK query code-splitting guidelines; injectEndpoints are good fit.
On libs/features-a, I have featureAQuery. My utility functions need to pass the store object or dispatch to the params, and it'd be better if the response can be inferred from the query definition
Question:
What is the type of SlicedQueryRootState, SlicedQueryRootDispatch?
Note that I'm not importing the root
storedue to circular dependency problemsBeta Was this translation helpful? Give feedback.
All reactions