RT
我最后改成了return put(action)就好了,这是为啥呢?
app.js中componentDidMount:
componentDidMount(){
store.subscribe(this.handlesubscription.bind(this));
let mock = new MockAdapter(axios);
mock.onGet('/todos').reply(200,{
data:'this is mockup'
});
const action = getTodos();
store.dispatch(action);
}
handlesubscription = prevState=>{
this.setState(store.getState())
}
actionCreators.js中的action
import { createAction } from '@reduxjs/toolkit';
import {GET_TODOS} from './actionlib'
export const getTodos = createAction(GET_TODOS)
sagas.js代码
import {takeEvery, put} from 'redux-saga/effects'
import {UPDATE_ITEM_INPUT, SUBMIT_ITEM_INPUT, DELETE_ITEM_DATA, GET_TODOS} from './actionlib'
import {getTodos} from './actionCreators'
import axios from 'axios';
function* getTodos_saga(){
const res = yield axios.get('/todos');
const action = yield getTodos(res.data.data);
return put(action);
}
function* mySaga() {
yield takeEvery(GET_TODOS, getTodos_saga);
}
export default mySaga;