redux saga 异步请求死循环,求帮忙看看

刚入坑,点击按钮抓取数据,陷入无限发请求,帮忙看看
想要的效果是 打开请求之前打开loading,完成后关闭loading
const TABLE_GET = "table_get";
const getAction = () => ({

type: TABLE_GET,
rows,
loading,

});
const defaultState = {

rows: [],
loading: false,

}
const moduleC = (state = defaultState, action) => {

const { type, rows, loading } = action;
switch (type) {
    case TABLE_GET:
        return { ...state, rows, loading };
    default:
        return state;
}

}
export default moduleC;

import { takeEvery, put } from 'redux-saga/effects';
import axios from 'axios';
function* tableGet(action) {

try {
    yield put({
        ...action,
        loading: true,
    });
    const result = yield axios.get("http://jsonplaceholder.typicode.com/posts");
    yield put({
        ...action,
        loading: false,
        rows: result.data
    });
} catch (error) {
    console.log("获取失败!");
    yield put({
        ...action,
        loading: false,
    });
}

}
function* mySaga() {

yield takeEvery(TABLE_GET, tableGet);

}
export default mySaga;

ui组件:
const module = props => {

const { getAction } = props;
return (
    <Fragment>
        <button onClick={getAction}>获取</button>
    </Fragment>
);

}
const dispatchToProps = {

getAction,

}
export default connect(null, dispatchToProps)(module);

阅读 4.2k
1 个回答
✓ 已被采纳新手上路,请多包涵

刚刚发现,put了好几个同样的TABLE_GET,导致死循环。。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题