Created
September 5, 2016 16:12
-
-
Save tricoder42/c8672e4d0f67865e8235cb1d09af23d8 to your computer and use it in GitHub Desktop.
How to react on state changes using redux-saga
This file contains 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
// just a helper function | |
const updateComponent = (component, newState) => component.setState(newState) | |
// 1st approach using redux-promise. Actions returns promises, so component | |
// can trigger actions when promise is resolved. | |
const handleEventPromise = (props) => (event) => { | |
this.props.action({...}) | |
.then((payload) => updateComponent(this, {...})) | |
} | |
// 2nd approach using redux-saga. All promises are resolved inside saga. | |
const handleEventSaga = (props) => (event) => { | |
this.props.action({...}) | |
// how to trigger updateComponent({...}) ? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment