【发布时间】:2020-07-03 03:21:08
【问题描述】:
我有一些代码需要更新。这不是我的代码,所以我不想要太多更改。它使用 redux-saga 和 axios。我想向 saga 传递一些参数
我在 sagas.js 中的传奇
export function* getInfoSaga() {
while (true) {
yield take(mutations.GET_INFO);
const url1 = `${url}/api/getInfo/1-100`;
const logInfo = yield axios.get<any>(url1).then(response => response);
yield put(mutations.setInfo(logInfo.data.data));
}
}
mutations.js
export const GET_INFO = 'GET_INFO';
export const getInfo = () => ({
type: GET_INFO,
});
sagas 在 index.js
中运行const s = sagas as any;
for (const saga in s) {
sagaMiddleware.run(s[saga]);
}
在某些文件中,该操作由带有事件的按钮运行:
onClick={() => dispatch({
type: 'GET_INFO',
})}
我想传递一些参数来修改请求 url,我尝试在 dipatch 请求中获取附加对象,并将参数添加到 sagas.js 和 mutatuions.js 中的生成器,但是我得到了一个错误 cannot access prperty of undefined
【问题讨论】:
标签: javascript reactjs typescript react-redux redux-saga