Last active
December 7, 2016 02:33
-
-
Save rfinni/2afcaf5dacccdf0765b3e17b5a0d42f8 to your computer and use it in GitHub Desktop.
Axios.all() usage with redux-thunk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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