如何以redux形式传递动态表单名称? [英] How do you pass in a dynamic form name in redux form?

查看:95
本文介绍了如何以redux形式传递动态表单名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用此代码将动态表单名称传递给reduxForm。

Im trying to use this code to pass a dynamic form name into reduxForm.

以下是我找到的代码:

let FormAddress = compose(connect((state, props) => ({form: props.form})), reduxForm({destroyOnUnmount: false, asyncBlurFields: []}))(ValidationForm);

从这篇文章:
https://github.com/erikras/redux-form/issues/603#issuecomment-254271319

但我不确定最新情况。

这就是我目前正在做的事情:

This is how I'm currently doing it:

const formName = 'shippingAddress';
const form = reduxForm({
  form: formName
});

export default connect(mapStateToProps)(CityStateZip);

但我希望能够使用道具传递它,如下所示:

But I would like to be able to pass it in using props, like this:

const formName = 'shippingAddress';
const form = reduxForm({
  form: props.form
  // validate
});

export default connect(mapStateToProps)(CityStateZip);

但是当我尝试这个时,它会抱怨它不知道道具是什么 - 因为我相信它在外面上述功能的范围。

But when I try that, it complains that it doesnt know what props is - because I believe it's outside the scope of the function above.

有人可以帮助我吗?

推荐答案

调用 FormAddress 组件的父组件应该在props中发送表单的名称为 props.form

The parent component which calling the FormAddress component should send the name of the form in props as props.form:

var formId="SomeId"
<FormAddress form={formId} />

// and in your FormAddress component have 
const form = reduxForm({
  //no need to put form again here as we are sending form props.
});

这对我有用。

这篇关于如何以redux形式传递动态表单名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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