Skip to content

Instantly share code, notes, and snippets.

@tricoder42
Created September 5, 2016 16:12
Show Gist options
  • Save tricoder42/c8672e4d0f67865e8235cb1d09af23d8 to your computer and use it in GitHub Desktop.
Save tricoder42/c8672e4d0f67865e8235cb1d09af23d8 to your computer and use it in GitHub Desktop.
How to react on state changes using redux-saga
// 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