markdalgleish / redial

Universal data fetching and route lifecycle management for React etc.
1.1k stars 42 forks source link

multiple dispatches inside fetch #43

Open walshe opened 7 years ago

walshe commented 7 years ago

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 = {

/**

hnq90 commented 7 years ago

@walshe You should try Promise

walshe commented 7 years ago

example ?

EJIqpEP commented 7 years ago

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

const redial = {
  fetch: ({ dispatch }) => Promise.all([
    dispatch(fetchCurrentUser()),
    dispatch(fetchCategories())
  ])
}
ngocketit commented 7 years ago

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 commented 7 years ago

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

Aryk commented 7 years ago

@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?