Skip to content

Instantly share code, notes, and snippets.

@amitmbee
Forked from kgrz/catch.ex.js
Created March 22, 2018 06:00
Show Gist options
  • Select an option

  • Save amitmbee/cb01f8a725491b7e4d0df1b3e89a44e5 to your computer and use it in GitHub Desktop.

Select an option

Save amitmbee/cb01f8a725491b7e4d0df1b3e89a44e5 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