How do you pass in a dynamic form name in redux form?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 06:07:02
Parameshwar Ande

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.
});

This works for me.

That snippet basically uses the compose function from redux library. Here's something you can try...

<FormAddress name="shippingAddress" />

So in your components/FormAddress.js file

import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { reduxForm } from 'redux-form';

class FormAddress extends React.Component { ... }

const mapStateToProps = (state, ownProps) => {
    return {
        form: ownProps.name,
        // other props...
    }
}

export default compose(
    connect(mapStateToProps),
    reduxForm({
        //other redux-form options...
    })
)(FormAddress);

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!