我可以使用 redux-form 自动调用 handleSubmit 以响应状态更改吗?

Can I automatically call handleSubmit in response to a state change using redux-form?

我希望我的 redux-form 有一个两部分提交策略。首先,用户在调用验证方法的表单上调用提交。响应可能有一些警告。我希望用户看到警告(如果有),并可选择继续另一个提交,这将是对服务器 rest api.

的真实 POST

如果没有警告,我希望组件自动提交。我正试图从 componentWillReceiveProps 方法开始。

问题是 nextProps.handleSubmit(this.doSubmit2of2); 没有调用 this.doSubmit2of2。执行只是跳过那个调用。

componentWillReceiveProps(nextProps) {        

    //boolean that indicates validation just occured against the server
    if (nextProps.storeWithValidation) {

        //the user hit submit, first it was validated, if no issues, go ahead and try to create
        if (nextProps.storeValidationOk) {
            //fire off create store
            nextProps.handleSubmit(this.doSubmit2of2);
        }
        else {
            //there are validation issues of some kind, let the user see them
            //do nothing here and let the render method do its thing with the props
        }
    }
}

我在这里找到了讨论:https://github.com/erikras/redux-form/issues/67,但在我的例子中,提交是由于特定的服务器响应而发生的。另外,我意识到 redux-form 有验证功能。我的设计是否超出了预期的框架约定?

此外,我考虑过重新设计我的服务器 api,但我想知道在服务器响应后自动重新提交的当前方法可以走多远。

据我了解,您想在服务器响应后远程提交表单。您可以在此 example from the docs 之后创建远程提交。然后你可以 dispatch(submit('yourFormName')) 任何时候你想要多少次都可以。