Skip to content

Instantly share code, notes, and snippets.

@rfinni
Last active December 7, 2016 02:33
Show Gist options
  • Select an option

  • Save rfinni/2afcaf5dacccdf0765b3e17b5a0d42f8 to your computer and use it in GitHub Desktop.

Select an option

Save rfinni/2afcaf5dacccdf0765b3e17b5a0d42f8 to your computer and use it in GitHub Desktop.
Axios.all() usage with redux-thunk.
export function reduxThunk(data) {
return function(dispatch, getState) {
// Gather all the requests into an array
const fileArr = [];
fileRequests.map((file, i) => {
return fileArr.push(axios.get(file.raw_url));
});
// Dispatch the action once all requests have finished
return axios.all(fileArr).then((files) => {
dispatch(someAction(files));
});
}
}
handleCLick() {
this.props.dispatch(reduxThunk(this.props.data));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment