How do you pass in a dynamic form name in redux 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.});
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!