Javascript 带while循环的redux调用api
我是这样给调度部打电话的:Javascript 带while循环的redux调用api,javascript,reactjs,redux,Javascript,Reactjs,Redux,我是这样给调度部打电话的: dispatch(check_data()) 我的职能是: export function get_data(){ return (dispatch, getState) => { return dispatch(myApi({url: `myurl`, method: "GET"} )).then(response => { return response.json() }).then(response
dispatch(check_data())
我的职能是:
export function get_data(){
return (dispatch, getState) => {
return dispatch(myApi({url: `myurl`, method: "GET"}
)).then(response => {
return response.json()
}).then(response => {
return response
})
}
}
export function check_data(){
return dispatch => {
var status = null;
var api_response;
while(status != 7102){
console.log("checking api response")
setTimeout(function(){
console.log("dispatching now ")
dispatch(get_data()).then(response => {
console.log(response)
status = response.status
console.log("printing status")
console.log(status)
api_response = response
})
}, 7000)
}
console.log("printing api response")
console.log(api_response)
dispatch(reset_data())
return api_response
}
}
当我这么做的时候。。它进入无限循环
我只想检查状态
是否不等于7102
它应该再次检查数据。如果找到,它应该返回响应
这里出了什么问题???您的代码完全错误,请尝试使用此库为什么发送大量事件,最好将所有项目作为数组,并在找到正确的状态时发送1个事件您能用我的上述代码详细说明或给我提示吗??