【发布时间】:2019-07-13 14:33:28
【问题描述】:
点击一个按钮,我发送一个动作来发出一个获取请求,我想在继续之前等待请求完成,这样做的正确方法是什么? 我确实根据我的传奇中的结果调度了一个动作:
function* workerSaga() {
try {
const response = yield call(fetchCall);
const myData= response.data;
// dispatch a success action to the store
yield put({ type: "API_CALL_SUCCESS", myData});
} catch (error) {
// dispatch a failure action to the store with the error
yield put({ type: "API_CALL_FAILURE", error });
}
但是我如何在发送请求操作的代码中知道获取请求已经完成?
提前谢谢。
编辑:
如果没有 saga,请求看起来类似于:
axios.get(myURL)
.then(/*here we know the request has finished*/);
与传奇:
this.props.dispatch({type:"API_CALL"})
//here i would like to know the request has finished
【问题讨论】:
-
您能否详细说明“发送请求操作的代码”?也许您可以在问题正文中提供该代码。了解更多关于您要完成的工作也会有所帮助。
-
我试图更好地解释我在问什么
标签: reactjs redux generator redux-saga