title: How to change a field in a redux-form?
body: <p>In my react component I am trying to set a field called 'total'. I have imported the change action as a prop into my component:</p>
  
  <pre><code>import React, { Component, Fragment } from 'react'
  import { Field, FieldArray, reduxForm, getFormValues, change } from 'redux-form'
  import { connect } from 'react-redux'
  import { CalcTotal } from './calculationHelper';
  
  
  
  const renderField = ({ input, label, type, meta: { touched, error } }) =&gt; (
    &lt;div&gt;
      &lt;label&gt;{label}&lt;/label&gt;
      &lt;div&gt;
        &lt;input {...input} type={type} placeholder={label} /&gt;
        {touched &amp;&amp; error &amp;&amp; &lt;span&gt;{error}&lt;/span&gt;}
      &lt;/div&gt;
    &lt;/div&gt;
  )
  
  const renderMods = ({ fields, meta: { error, submitFailed } }) =&gt; (
    &lt;Fragment&gt;
      &lt;ul&gt;
        &lt;li&gt;
          &lt;button type="button" onClick={() =&gt; fields.push({})}&gt;
            Add Modification
        &lt;/button&gt;
          {submitFailed &amp;&amp; error &amp;&amp; &lt;span&gt;{error}&lt;/span&gt;}
        &lt;/li&gt;
        {fields.map((mod, index) =&gt; (
          &lt;li key={index}&gt;
            &lt;button
              type="button"
              title="Remove Mod"
              onClick={() =&gt; fields.remove(index)}
            /&gt;
            &lt;h4&gt;Mod #{index + 1}&lt;/h4&gt;
            &lt;Field
              name={`${mod}.lastYear`}
              type="number"
              component={renderField}
              label="Last Year"
            /&gt;
            &lt;Field
              name={`${mod}.currentYear`}
              type="number"
              component={renderField}
              label="Current Year"
            /&gt;
  
  
  
            &lt;Field name={`${mod}.type`} component="select" label="Type"&gt;
              &lt;option /&gt;
              &lt;option value="-"&gt;Expense&lt;/option&gt;
              &lt;option value="+"&gt;Income&lt;/option&gt;
              &lt;option value="-"&gt;Tax&lt;/option&gt;
            &lt;/Field&gt;
  
  
          &lt;/li&gt;
        ))}
      &lt;/ul&gt;
  
      &lt;Field
        name="total"
        type="number"
        component="input"
        label="Total modifications"
        text="0"
      /&gt;
  
    &lt;/Fragment&gt;
  )
  
  
  class FieldArraysForm extends Component {
  
  
  
    render() {
      const { handleSubmit, formValues, change } = this.props
  
  
  
      if (formValues) {
        console.log('formvalues', formValues);
        const test = CalcTotal(2000);
        console.log('calc=', test);
        debugger
        this.props.change('fieldArraysForm', 'total', 5000)
      }
  
      return (
        &lt;form onSubmit={handleSubmit}&gt;
  
          {/* &lt;button onClick={this.changeStuff}&gt;set total&lt;/button&gt; */}
  
          &lt;FieldArray name="mods" component={renderMods} /&gt;
  
  
  
  
          &lt;div&gt;
            &lt;button type="submit" &gt;
              Submit
          &lt;/button&gt;
  
          &lt;/div&gt;
        &lt;/form&gt;
      )
    }
  }
  
  
  
  const mapStateToProps = (state) =&gt; ({
    formValues: getFormValues('fieldArraysForm')(state),
  });
  
  const mapDispatchToProps = {
    change
  };
  
  
  // const Example = reduxForm({
  //   form: 'fieldArraysForm', // a unique identifier for this form
  // })(FieldArraysForm)
  
  // const ConnectedForm = connect(
  //   mapStateToProps,
  //   mapDispatchToProps,
  // )(Example);
  
  // export default ConnectedForm
  
  export default reduxForm({
    form: "fieldArraysForm"
  })(
    connect(
      mapStateToProps,
      mapDispatchToProps
    )(FieldArraysForm)
  );
  </code></pre>
  
  <p>The line where the code fall into an infinite loop:</p>
  
  <pre><code>this.props.change('fieldArraysForm', 'total', 5000)
  </code></pre>
  
  <p>How /where do I put this statement to make sure the 'total' field is changed and not get into a loop?Which React lifecycle event would suit? I want to fire this whenever there is a form change on any field.</p>