Skip to content

Instantly share code, notes, and snippets.

@kgrz
Created August 7, 2017 10:24
Show Gist options
  • Select an option

  • Save kgrz/c4be3885c99c70caf967fe4f28d32d10 to your computer and use it in GitHub Desktop.

Select an option

Save kgrz/c4be3885c99c70caf967fe4f28d32d10 to your computer and use it in GitHub Desktop.
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