Current RTK version and TypeScript #22
Replies: 2 comments 7 replies
-
Hello @AnnoDomine,
export const reducers = {
project: projectSlice.reducer,
content: contentReducer,
loading: loadingReducer,
theme: themeReducer,
tab: tabReducer,
};
export const prepared = prepareStore({
reducers,
sagas: { projectApi: fetchApi.saga() },
onError: (err) => console.log(err),
});
const sagaMiddleware = createSagaMiddleware({});
safeMiddleware = ... //your middlewares
function setupStore() {
const store = configureStore({
reducer: prepared.reducer,
devTools: process.env.NODE_ENV !== "production",
middleware: safeMiddleware,
});
prepared.run();
return store;
}
const store = setupStore();
const persistor = persistStore(store);
export function AppSore({ children }) {
sagaMiddleware.run(rootSaga); // other sagas you may have, in the existing project
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
{children}
</PersistGate>
</Provider>
);
}
export type PersistorState = ReturnType<typeof persistor.getState>;
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch &
((actions: AnyAction[]) => AnyAction[]); I am sure that there could be an even cleaner way to setup an existent codebase made with RTK and/or Robodux as well. |
Beta Was this translation helpful? Give feedback.
-
@VldMrgnn okay. I have a good news and i have a problem ^^ First of all the good things.
In the code above you see i commented the problem i have. I need to delay the refetch with 1 sec -.- |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks.
While i tried to upgrade my rtk and saga setup with saga-query i had some problems but could solv them.
My experience i want to share with you.
RTK configureStore (instead using depricated createStore):
the store buildup is a little bit other in the current version than befor.
"createStore" is depricated and should not use anymore.
First i hab problems to inject the saga-query prepaired store into the current store.
But i figured out that you can inject the prepaired store with the current reducers without setting up the slices with saga-query:
prepairedStore.ts
store.ts
As you see my project reducer is build with saga-query and the rest are direct imports of the slices.
TypeScript:
This was a little bit strange youse the basic RootState type which documented in RTK-documentation is with saga-query in this form not posible.
But there is an easy answer.
Instead of using
typeof store
use the prepaired store reducers.So the types are correct again.
I hope i could give a few hinds for possible problems to someone who had the same problems than me.
Spezialy when you add saga-query into an almost builded project.
I hope the contributer will finish this project.
Greetz
Beta Was this translation helpful? Give feedback.
All reactions