在新的 Redux 模板反应应用程序中使用 Redux-Saga

Using Redux-Saga in New Redux template react app

新的 redux 有一个内置的 store 模板和启动 react redux 应用程序所需的所有东西,但它在后台使用 redux-thunk 进行异步调用。它不可能用 redux-saga 而不是 thunk 来替换它。

Redux Toolkit 允许您 customize the list of middleware you're using using the middleware option of configureStore,就好像您正在使用基础 createStore API.

创建 Redux 商店一样

您可以通过提供自己的 middleware 数组来完全替换 default list of pre-defined middleware,或者调用 getDefaultMiddleware() 并将您自己的中间件添加到数组并使用它。

所以,我的建议是:

const store = configureStore({
  reducer: rootReducer,
  middleware: getDefaultMiddleware().concat(sagaMiddleware)
})