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

multiple dispatches inside fetch #43

Open
walshe opened this issue Jan 4, 2017 · 6 comments
Open

multiple dispatches inside fetch #43

walshe opened this issue Jan 4, 2017 · 6 comments

Comments

@walshe
Copy link

walshe commented Jan 4, 2017

finally realised after anout 2 weeks that a return is needed on the last dispatch (if you have multiple dispatches) inside the fetch.

Why is this exactly ? might be no harm to put in the docs btw

`const redial = {

/**

  • this is triggered from server/index.js
    */
    fetch: ({ dispatch, params: {filter} }) => {

     //get filter data
     dispatch(loadFilterData())
    
     //kick off a default search
     return dispatch(loadUnlistedVins())
    

    }
    }`

@hnq90
Copy link

hnq90 commented Jan 13, 2017

@walshe You should try Promise

@walshe
Copy link
Author

walshe commented Jan 13, 2017

example ?

@EJIqpEP
Copy link

EJIqpEP commented Jan 22, 2017

Had the same problem. @hnq90 just use Promise.all

const redial = {
  fetch: ({ dispatch }) => Promise.all([
    dispatch(fetchCurrentUser()),
    dispatch(fetchCategories())
  ])
}

@ngocketit
Copy link

So does this mean dispatch needs to return a Promise? Does it work with redux-api-middleware? I'm thinking about switching over to redial

@ngocketit
Copy link

Oh yes, the promise is stated in the doc. Any one having this work with redux-api-middleware?

@Aryk
Copy link

Aryk commented Apr 17, 2017

@EJIqpEP

Just curious, in your example, if fetchCurrentUser, returns a Promise, do you need special middleware so that dispatch(fetchCurrentUser()) returns a Promise or does this just work out of the box?

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

No branches or pull requests

5 participants