是否可以/安全地使用带有承诺的处理程序?例:
withHandlers({
onChange: props => event => {
props.callAPI(props.data)
.then(data => props.updateData(data))
},
...
Run Code Online (Sandbox Code Playgroud)
谢谢!
经过一些测试,我意识到它运行得很好。用纯成分重组岩石以进行建筑。
这是完全有效的并且工作得很好。
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);
Run Code Online (Sandbox Code Playgroud)
它帮助我克服了无法将Apollo 客户端的 graphQl 突变结果反映到包装组件的问题。这可以完美地处理它,并且不需要组件本身产生副作用。