Last active
September 4, 2015 14:02
-
-
Save bs1180/c06cc9e0f6d17456b9fe to your computer and use it in GitHub Desktop.
Dynamic forms in redux-form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class FormWrapper { | |
render () { | |
const Form = makeForm(['name', 'age', 'sex']); | |
return ( | |
<div> | |
<Form /> | |
</div> | |
) | |
} | |
} | |
function makeForm (fields) { // this could also take the other values required by the reduxForm config, eg. form name | |
class MyForm { | |
static defaultProps = { | |
fields: {} | |
} | |
render() { | |
const fieldList = Object.keys(this.props.fields).map(k => { | |
return <input key={k} {...this.props.fields[k]} /> | |
}) | |
return ( | |
<form> | |
{ fieldList } | |
</form> | |
) | |
} | |
} | |
return connectReduxForm({form: 'dynamic', fields: fields})(MyForm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment