1

In the initialze action we pass an object which tell the forma name and the initial values. But how does it understand which value will be for which Field.

Like if I have 5 Fields in the redux form and want to initialze only 2 Fields. Then how will the initialze action will understand for which Field the initial values are provided.

https://redux-form.com/8.2.2/docs/api/props.md/#-code-initialize-data-object-function-code-

1
  • Please also keep in mind, if you are just learning Redux, that it is generally not recommended (for years) to keep forms in Redux and even redux-form has a message in the front page of their documentation suggesting to use another library that works without Redux. If you are following a Redux tutorial now that shows you redux-form, it is horribly outdated. For up-to-date Redux tutorials, see the official docs at redux.js.org/tutorials/essentials/part-1-overview-concepts Commented Apr 29, 2021 at 6:57

1 Answer 1

1

In the initialze action we pass an object which tell the forma name and the initial values. How does it understand which value will be for which Field.

The object with initial values will (it should) have keys that match the field input name attributes.

Example:

<Field
  autoComplete="email"
  component={RenderTextField}
  id="login-email"
  label={formatMessage(strings.loginUsername)}
  name="email"
  type="text"
/>

If the form is initialized with initialize('login', { email: state.emailAddress }); it will match/assign the state.emailAddress to the value of the input with matching name attribute, email in this case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.