我正在尝试链接 2 个 api 调用,第一个是创建新服务的 POST,第二个是使用正确的用户/管理员调用更新该服务。
但是它永远不会到达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) } )
关于javascript - 第二个链式 API 未被调用(React + Axios),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45827827/