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

Calling two API's in the same time #177

Open
paveu opened this issue Mar 18, 2018 · 1 comment
Open

Calling two API's in the same time #177

paveu opened this issue Mar 18, 2018 · 1 comment
Labels

Comments

@paveu
Copy link

paveu commented Mar 18, 2018

Hi,
I have two API calls in the componentDidMount(). I want to wait until they are all finished before component mounts in. Is there efficient way to do it ? is there something like Promise.all() available?

Thanks,
Pawel

@nason nason added the question label Mar 22, 2018
@nason
Copy link
Collaborator

nason commented Jul 11, 2018

Sure you can! Something like this should work in componentDidMount:

Promise.all([
  dispatch(requestCreatorOne()),
  dispatch(requestCreatorTwo())
]).then(results) => {
  if(results.some(r => r.error)) {
   // If there are any errors in the response, you could trigger an error path like so
   dispatch(componentFetchError())
   // OR by connecting the component to relevant redux store properties set by the request actions
  } else {
   // Otherwise, signal the UI that it should proceed
   dispatch(componentFetchSuccess())
    // OR connect your component to redux state set by the request actions
  }
})

Let me know if that helps!

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

No branches or pull requests

2 participants