Created
August 7, 2017 10:24
-
-
Save kgrz/c4be3885c99c70caf967fe4f28d32d10 to your computer and use it in GitHub Desktop.
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
| function anAction () { | |
| return function (dispatch) { | |
| dispatch(requestStarted()) | |
| return fetch().then( | |
| function (success) { | |
| dispatch(requestWasSuccessful(success)); | |
| }, | |
| function (error) { | |
| dispatch(requestFailed(success)); | |
| } | |
| ); | |
| } | |
| } | |
| class SomeComponent extends Component { | |
| componentDidMount () { | |
| anAction(); | |
| } | |
| render () { | |
| const { | |
| actionData | |
| } = props; | |
| <div>Whut</div> | |
| } | |
| } | |
| // mapstatetoprops that maps the redux data to props | |
| // | |
| class SomeOtherComponent extends Component { | |
| componentDidMount () { | |
| const { actionData } = this.props; | |
| anAction().then(function(success) { | |
| // we know that this is successful, so call something that's | |
| // required. | |
| if (actionData.shouldCallTheOtherAction) { | |
| callAnotherAction(actionData.someRandomStuff) | |
| } | |
| }); | |
| } | |
| render () { | |
| const { | |
| actionData | |
| } = props; | |
| <div>Whut again</div> | |
| } | |
| } | |
| // mapstatetoprops that maps the redux data to props |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment