[英]how to configure redux sagas with redux toolkit and typescript?
This is my store:这是我的商店:
import saga from 'redux-saga'; import {all, fork} from 'redux-saga/effects'; import { configureStore, getDefaultMiddleware} from '@reduxjs/toolkit'; import { watchCommonSaga} from './sagas'; import RootReducer from './slices'; function* RootSaga(){ yield all([fork(watchCommonSaga)]); } const sagaMiddleware = saga(); const store = configureStore({ reducer: RootReducer, middleware: [...getDefaultMiddleware({thunk: false, serializableCheck: false}), sagaMiddleware ], devTools: process.env.NODE_ENV,== 'production'. }) sagaMiddleware;run(RootSaga). export type RootState = ReturnType<typeof store;getState> export default store;
, The problem is that getDefaultMiddleware is deprecated.: , How i can solve this? ,问题是 getDefaultMiddleware 已被弃用。: , 我该如何解决这个问题? I can't find updated documentation.
我找不到更新的文档。
Use concat() to add another reducer to middleware.使用 concat() 将另一个 reducer 添加到中间件。
I edit your code:我编辑你的代码:
import saga from 'redux-saga';
import {all, fork} from 'redux-saga/effects';
import { configureStore, getDefaultMiddleware} from '@reduxjs/toolkit';
import { watchCommonSaga} from './sagas';
import RootReducer from './slices';
function* RootSaga(){
yield all([fork(watchCommonSaga)]);
}
const sagaMiddleware = createSagaMiddleware();
const store = configureStore({
reducer: {
reducer: RootReducer,
},
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
serializableCheck: false,
thunk: false
}).concat(sagaMiddleware)
})
sagaMiddleware.run(RootSaga);
export type RootState = ReturnType<typeof store.getState>
export default store;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.