Skip to content

Modularize RTK App #1845

Answered by sam-mfb
sam-mfb asked this question in Q&A
Dec 18, 2021 · 7 comments · 22 replies
Discussion options

You must be logged in to vote

I cleaned up the typing and added some documentation. Here's the full solution, which is also on the repo (suggestions and improvements welcome):

// RootStateInterface is defined as including at least this slice and any other slices that
// might be added by a calling package
type RootStateInterface = { counter: CounterState } & Record<string, any>;

// A version of AppThunk that uses the RootStateInterface just defined
type AppThunkInterface<ReturnType = void> = ThunkAction<
  ReturnType,
  RootStateInterface,
  unknown,
  Action<string>
>;

// A version of use selector that includes the RootStateInterface we just defined
export let useSliceSelector: TypedUseSelectorHook<RootStateInterface>

Replies: 7 comments 22 replies

Comment options

You must be logged in to vote
2 replies
@markerikson
Comment options

@sam-mfb
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
15 replies
@omdxp
Comment options

@sam-mfb
Comment options

@omdxp
Comment options

@sam-mfb
Comment options

@omdxp
Comment options

Answer selected by markerikson
Comment options

You must be logged in to vote
1 reply
@markerikson
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@umashankar-pardhi-amla
Comment options

@sam-mfb
Comment options

@upardhi
Comment options

@sam-mfb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants