Possible Unhandled Promise Rejection: Error: Actions must be plain objects. Use custom middleware for async actions

Possible Unhandled Promise Rejection: Error: Actions must be plain objects. Use custom middleware for async actions

我有一个函数,旨在根据设置的输入执行各种异步操作。这是我的功能:

const generalApiRequest =(requestUrl, urlType, data={},actionDispatch) =>{
    
  return function(dispatch, getState){
      
      console.log(dispatch);
      adminId = getState().authentication.adminId;
      token = getState().authentication.token;
      
      return hitUrl(requestUrl,urlType, dispatch, data).then((response)=>{
          try{
          if(response.status === 200){
              //dispatch(actionDispatch(response.data));
              actionDispatch();
          } 
          else{
            console.log("Wrong response",response);
            if(response.status === 401){
              console.log('login again, auth failed');
              dispatch(authFailed());
            }
          }
        }
        catch(error){
          console.log(error);
         }
        }
        ,(error)=>{console.log(error)})
     
  }
  
};

这里还有函数需要的 hitUrl() :

const hitUrl= async function(requestUrl, urlType,dispatch, data={}){
  try {
    //const requestUrl = apiUrl+ 'application/fetch-dashboard-data'+`/{$adminId}`;
    if(urlType === "get"){
      response = await axios(requestUrl,header(token));
    }
    else {
      response= await axios.post(requestUrl, data, header(token));
    }
     
    return response;
  } catch (error) {
    console.log(error);
          console.log("error status", error.response.status);
          try{
            if(error.response.status === 401){
              dispatch(authFailed());
            }
          }
          catch(newError){
            console.log(newError)
          }
          
  }
 }

我还有函数 processApplicant()

export const processApplicant=(data)=>{
  let requestUrl;
  let urlType = "post";
  let message;
  message = "The user has been successfully deleted"
  requestUrl = apiUrl+ 'application/process/delete';
  let actionDispatch= triggerSuccess(message);
  generalApiRequest(requestUrl,urlType, data, actionDispatch);
}

现在我在我的 React 组件中发送了下面的动作

dispatch(processApplicant({adminId: 2, comment: "No comments", trigger: "Pick", userId: 3}));

这样做时,我得到了上面标题中的错误(可能未处理的承诺拒绝:错误:操作必须是简单的 objects。使用自​​定义中间件进行异步操作)。 我有 redux thunk 作为中间件,它可以很好地满足其他请求。请问我做错了什么?

您的processApplicant设置不正确。

export const processApplicant = (data) => {
    return (dispatch) => {
        let requestUrl;
        let urlType = "post";
        let message;
        message = "The user has been successfully deleted"
        requestUrl = apiUrl + 'application/process/delete';
        let actionDispatch = triggerSuccess(message);
        dispatch(generalApiRequest(requestUrl, urlType, data, actionDispatch));
    }

}