Skip to content

Instantly share code, notes, and snippets.

@bs1180
Last active September 4, 2015 14:02
Show Gist options
  • Save bs1180/c06cc9e0f6d17456b9fe to your computer and use it in GitHub Desktop.
Save bs1180/c06cc9e0f6d17456b9fe to your computer and use it in GitHub Desktop.
Dynamic forms in redux-form
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