redux-form/redux-form

Possibility to change many fields simultaneously using props.change?

Open

#3737 opened on Jan 10, 2018

View on GitHub
 (7 comments) (54 reactions) (0 assignees)JavaScript (12,592 stars) (1,683 forks)batch import
c:action-creatorsenhancementhelp wanted

Description

Hi guys,

Just want to say that redux-form has been really helpful for us in our project and is an integral part of our web assets. Couldn't imagine the nightmare of handling all of form states manually.

On the other hand, I just noticed this behaviour with props.change that every time it's called, it will re-render the entire form, which makes sense and to be expected.

But, what happens is in our use case, we have some sort of master field that controls multiple fields under it. (It sets a default value calculated using custom formula based on the master field value) The connection between them is through props.change. So that means I have this code:

function onMasterFieldChange() {
  this.props.change('field1', val1);
  this.props.change('field2', val2);
  this.props.change('field3', val3);
  this.props.change('field4', val4);
  //...may increase in time
}

Note that the number of the child fields is dynamic, so that means that props.change called by onMasterFieldChange() will increase in time, and the form itself is getting larger. This ultimately leads to render() being called so many times every time onMasterFieldChange() is triggered which causes significant slowdown after some field number.

I was thinking wouldn't be nice to change many fields simultaneously just by using one props.change, similar to how you can setState multiple keys in React. What do you guys think about this scenario?

Thanks

Contributor guide