1.npm install redux-saga
2.store/index的配置
引入createSagaMiddleware,创建SagaMiddleware
通过applyMiddleware使用中间件
创建sagas.js文件
引入sagas.Js文件
sagas.Js文件的书写
通过sagamiddleware运行sagas.js文件
import createSagaMiddleware from 'redux-saga';
import { createStore, compose, applyMiddleware } from 'redux';
import reducer from './reducer';
import todoSagas from './sagas';
const sagaMiddleware = createSagaMiddleware();
const composeEnhancers =
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
}) : compose;
const enhancer = composeEnhancers(
applyMiddleware(sagaMiddleware)
);
const store = createStore(reducer, enhancer);
sagaMiddleware.run(todoSagas);
export default store;
2.当做了配置后派发action时
componentDidMount() {
const action = getInitList();
store.dispatch(action);
}