Is is possible/safe to use withHandlers with promises? Ex.:
withHandlers({
onChange: props => event => {
props.callAPI(props.data)
.then(data => props.updateData(data))
},
...
Thanks!
After some tests I realized that it's working pretty well. Recompose rocks for building with pure components.
This is perfectly valid and working pretty well.
const enhWithHandlers = withHandlers({
loginUserMutation: props => args => {
props.updateMutationState(loading: true, error: null });
props.loginUser(args)
.then(() =>
props.updateMutationState({loading: false, error: null }))
.catch(err =>
props.updateMutationState({ loading: false, error: err }));
}
},
...
// then compose like
export default compose(
reduxConnect,
gqlConnectLogin,
gqlConnectRegister,
enhWithState,
enhWithHandlers
)(UserLoginRegister);
It helps me to overcome lack of ability to reflect results of graphQl mutation with Apollo client to the wrapped component. This handles it perfectly and without the need of side effects in the component itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With