Reputation: 1374
UPDATE: It's not possible to solve from information I gave you, the problem is that code is updated in ComponentReceiveProps hook and original values overwrite changed values.
I work on project developed by external agency that didn't do the best job.
It is front-end application using React, Redux and Redux-Forms
There is one form that is used in two different pages. It works well in one page, but doesn't react in the other. I cannot change value of inputs by UI, neither by changeFieldValue
function. Redux state is not changed.
In both cases, the same component is used. It contains reduxForm
function.
const mapDispatchToProps = dispatch => ({
changeFieldValue: (field, value) => dispatch(change('ContractConsumption', field, value)),
});
class ContractConsumption extends React.Component {
// ...
}
ContractConsumption = reduxForm({
form: 'ContractConsumption',
enableReinitialize: true
})(ContractConsumption);
Any help would be appreciated. It's confusing to me, why the same component with redux form would work in one case and not in the other.
The whole code is overly complicated and heavily coupled, so it's not possible to share it easily or test it part by part.
Upvotes: 1
Views: 642
Reputation: 1568
It looks like you/agency didn't connect the form to the store:
import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import { connect } from 'react-redux';
class Example extends Component {
// ...
};
const mapStateToProps = (state) => ({
// ...
});
const mapDispatchToProps = (dispatch) => ({
// ...
});
Example = connect(
mapStateToProps,
mapDispatchToProps
)(Example);
export default reduxForm({
form: 'example' // a unique name for this form
})(Example);
See How do I mapStateToProps or mapDispatchToProps?
Upvotes: 2