我试图连接2个api调用,首先是一个创建新服务的POST,第二个是使用正确的用户/ admin调用UPDATE服务。
然而,它永远不会进入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))
}
思考?怎么可以重写呢?
答案 0 :(得分:2)
.then
将函数作为参数而不是函数调用。
尝试将链式then
更改为
// Then Update the Admin to have the Service and Rights
.then(res => { addUserToService(user) } )