Santhosh
Santhosh

Reputation: 11778

redux-form: enableReinitialize is not working

In my form I am passing the initialvalues through the below code. The initialvalues are being set. The initialization works only one time. after that the initialization values are not changing

const mapStateToProps1 = (state) => {
        return {
            initialValues : getValues(state.ingredients.formcomb.form.data)
         }
    }

const mapDispatchToProps1 = (dispatch) => {
    return {
        fetchData: (url) => dispatch(itemsFetchData(url)),
    };
};

 IngredientForm = connect( mapStateToProps1,mapDispatchToProps1 )(
      reduxForm(
      {
        form: 'ingredient',
        enableReinitialize: true,
        //validate,
      }
      )(IngredientForm)
 );

Upvotes: 2

Views: 2316

Answers (1)

Santhosh
Santhosh

Reputation: 11778

Even if i do enableReinitialize: true,, the values are not initialized if the form is submitted successfully.

Because when the form is submitted successfully it returns back the same initialvalues as previous. So there is no change in the state. If there is no change in the sate then the INITIALIZE action will not be called.

The only way to reinitialize a successfully submitted form is to use this.props.reset() if there are no form errors are returned.

I found the answer here: How can I clear my form after my submission succeeds?

Upvotes: 1

Related Questions