Redux form field component and validation

I use shorthand to hide and show components based on value.

The documentation for the Redux form states the following:

Connecting to multiple fields should be used sparingly, as this will require the entire component to be re-displayed each time one of the fields to which it is connected changes. This can be a performance bottleneck. If you absolutely do not need this, you must connect to your fields individually.

It is unclear whether my decision is to hide and show fields based on radio buttons in order to use Fields, so that the warning is used sparingly.

Can you clarify if my component deserves sufficient reason to use Fields. If not, what is an alternative way to implement?

Also, how Fieldsdoes it implement checks?

<div>
    <form>
      <Fields
       component={RadioButtonGroupField}
       names={['radioButtonGroup', 'nameTextField', 'nickNameTextField']}
      />
    </ form>
</div>

function RadioButtonGroupField(fields) {
    return(
      <div>
        <RadioButtonGroupComponent
          {...fields.radioButtonGroup.input}
          {...fields.radioButtonGroup.meta}
        />
        {
          (fields.radioButtonGroup.input.value === 'name' ||
          fields.radioButtonGroup.input.value === 'both') &&
          <NameTextFieldComponent
            {...fields.radioButtonGroup.input}
            {...fields.radioButtonGroup.meta}
          />
        }
        {
          (fields.radioButtonGroup.input.value === 'nickname' ||
          fields.radioButtonGroup.input.value === 'both') &&
           <NicknameTextFieldComponent
            {...fields.radioButtonGroup.input}
            {...fields.radioButtonGroup.meta}
          />
        }
      </div>
     );
  }
+6
source share
1 answer

There is another way that you could do by selecting a specific value using the reduction form selectors ( http://redux-form.com/6.0.5/docs/api/Selectors.md/ ) from the redux store in yours mapStateToProps, and then conditionally display specific components.

, , Fields - , . , , , 3- .

, Fields, , , : https://github.com/erikras/redux-form/issues/841

+1

Source: https://habr.com/ru/post/1016302/


All Articles