RTK: preloaded state and type inferring from store? #3368
Replies: 1 comment 3 replies
-
export type RootState = ReturnType<typeof slice.reducer>;
export const configure = (preloadedState?: RootState) => {
const store = configureStore({
preloadedState,
reducer: slice.reducer,
})
return store;
} |
Beta Was this translation helpful? Give feedback.
3 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.
-
As I can read from docs, preloaded state can be passed like this:
Also, docs speak about type inferring like this:
My question is how to combine these two things together. Because when I tried it, I came across a problem that module exports can be declared only in top level of the code (and it makes sense) but for passing a preloaded state, I need to create the store in a callback.
Is there some way how to tackle the problem? Or can I use only one or another feature? Couldn't find any mention about it somewhere.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions