Redux-form: How can I change a field of redux-form from parent component?

Created on 17 May 2016  路  3Comments  路  Source: redux-form/redux-form

I want to set some value for input in the redux-form in the parent component which wraps a form. How can I do i?

question

Most helpful comment

Well, to do it "from the parent component", you would pass the initialValues as a prop to the decorated form component.

All 3 comments

You should use initialValues to initialize a form (and its inputs).

reduxForm({
  form: "form",
  fields: ["username", "email"],
  initialValues: {
    username: "John",
    email: "[email protected]",
  }
})(
  props => (
    <form onSubmit={props.handleSubmit}>
      <input type="text" {props.fields.username} />
      <input type="email" {props.fields.email} />
      <button type="submit">Send</button>
    </form>
  )
)

Well, to do it "from the parent component", you would pass the initialValues as a prop to the decorated form component.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings