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 Fields
does 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>
);
}
source
share