第二个链接 API 没有被调用(React + Axios)

2nd chained API not getting called (React + Axios)

我正在尝试链接 2 个 api 调用,第一个是创建新服务的 POST,第二个是使用正确的 user/admin 更新该服务的调用。

然而它永远不会到达 api.updateUserRights

export const addService = (service, user, rights) => (dispatch) => {
  const params = {
    name: service,
    disabled: false,
    rights: rights
  };

  console.log('----------------- addService')
  console.log(' service', service)
  console.log(' user', user)
  console.log(' params', params)

  const addUserToService = (user) => api.updateUserRights(key, user);

  api.addService(service, params)
    // First Add the Service
    .then(res => {
      dispatch({
        type: actionTypes.ADD_SERVICE,
        payload: {
          service,
          rights
        }
      });
    })
    // Then Update the Admin to have the Service and Rights
    .then(addUserToService(user))
}

想法?这怎么能重写?

.then 将函数作为参数而不是函数调用。 尝试将链式 then 更改为

    // Then Update the Admin to have the Service and Rights
.then(res => { addUserToService(user) } )