Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this support dispatching more than 1 action on SUCCESS? #185

Open
christopher-francisco opened this issue May 25, 2018 · 2 comments
Open

Comments

@christopher-francisco
Copy link

On a "delete resource" context, Success need to call for loading once again. In my case, it also has to close the confirm dialog. Can I dispatch multiple actions on success?

@tkajtoch
Copy link

You shouldn't use redux-api-middleware's action types to dispatch such actions. However, you can catch the success action somewhere (you can choose from writing a middleware handling this, using redux-saga, and so on). redux-api-middleware allows you to pass a function to payload as well, which will be called on successful server response - you can experiment with placing a thunk into there but unfortunately, I didn't test it by myself.

@nason
Copy link
Collaborator

nason commented Jul 11, 2018

Would this approach work for you? (note: depends on redux-thunk)

dispatch(myRequestActionCreator()).then(action => {
  if (action.error) { 
    // handle error
  } else {
    return dispatch(followupActionCreator()) 
  }
})

See more at https://github.com/agraboso/redux-api-middleware#dispatching-thunks

Let us know if this helps, or if there's something you'd like better explained/documented!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants