Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带while循环的redux调用api_Javascript_Reactjs_Redux - Fatal编程技术网

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个事件您能用我的上述代码详细说明或给我提示吗??