在表单提交时调用异步 redux 操作创建者 [英] Calling an async redux action creator on form submission

查看:44
本文介绍了在表单提交时调用异步 redux 操作创建者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在典型的 React/Redux 应用程序中,使用 redux 是很常见的-thunk 和异步动作创建者触发 AJAX 请求并在此请求的启动/成功/失败时分派动作.

In a typical React/Redux app it's pretty common to use redux-thunk and async action creators to trigger an AJAX request and dispatch actions on start/success/failure of this request.

但是,我找不到将这样的功能与 react-final-form 集成的方法.它的 redux 提交示例 正在使用 react-redux-promise-listener 立即调度一个动作,但不让我调用我的异步动作创建者.

However, I can't find a way to integrate such a function with react-final-form. Its redux submission example is using react-redux-promise-listener which dispatches an action immediately, but does not let me call my async action creator.

是否可以将 react-final-form 与使用异步操作创建器执行提交时操作的 redux 应用程序集成?我宁愿不必将我的 AJAX 逻辑移到减速器中.

It is possible to integrate react-final-form with a redux app that uses an async action creator to perform the on-submit action? I would prefer not having to move my AJAX logic into the reducers.

推荐答案

表单库所关心的只是onSubmit 函数返回一个Promise.如果分派你的自定义动作创建者创建的动作可以返回一个承诺(也许通过一些中间件?),这就是 React Final Form 关心的.承诺侦听器库更多地用于副作用中间件,例如 Redux Saga.

All the form library cares about is that the onSubmit function returns a Promise. If dispatching your action created with your custom action creator can return a promise (perhaps via some middleware?), that’s all that React Final Form cares about. The promise listener library is more for side-effect middlewares, like Redux Saga.

这篇关于在表单提交时调用异步 redux 操作创建者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆