Leon Gaban Leon Gaban - 6 months ago 51
Javascript Question

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

I'm trying to chain 2 api calls, first is a POST which creates a new service, 2nd is a call to UPDATE that service with the correct user/admin.

However it's never making it to


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 => {
type: actionTypes.ADD_SERVICE,
payload: {
// Then Update the Admin to have the Service and Rights

Thoughts? How could this be re-written?

Answer Source

.then takes a function as a parameter and not a function call. Try changing the chained then to

    // Then Update the Admin to have the Service and Rights
.then(res => { addUserToService(user) } )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download