reactjs 如何在Redux-saga中使用configStore?

ev7lccsx  于 2022-12-12  发布在  React
关注(0)|答案(1)|浏览(165)

createStore工作正常。但在v18 react中,需要configStore。如何将configStore与redux-saga中间件一起使用
`

const SagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, applyMiddleware(SagaMiddleware));
SagaMiddleware.run(rootSaga);

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <Provider store={store}>
    <React.StrictMode>
      <BrowserRouter>
        <App />
        <ToastContainer position="top-center" />
      </BrowserRouter>
    </React.StrictMode>
  </Provider>
);

`

vulvrdjw

vulvrdjw1#

redux-starter-kit在默认情况下不包含sagaMiddleware [1]。您需要将其添加到中间件列表中并自己初始化saga。
import createSagaMiddleware from 'redux-saga'
import { configureStore, getDefaultMiddleware } from 'redux-starter-kit'
import rootReducer from '../reducers'
import { initSagas } from '../initSagas'

const sagaMiddleware = createSagaMiddleware();
export const store = configureStore({
  reducer: rootReducer,
  middleware: [...getDefaultMiddleware(), sagaMiddleware]
})
initSagas(sagaMiddleware);

我希望这对你有用

如果不通知我

相关问题