For example the Chips components only update state from props in constructor:
https://github.com/primefaces/primereac ... s/Chips.js
Code: Select all
constructor(props) {
super(props);
this.state = {values : props.value, focus: false}; //HERE IS THE PROBLEM
this.inputFocus = this.inputFocus.bind(this);
}
I had the case with the "reset" function of redux form:
Code: Select all
<Chips value={field_managed_by_redux} />
Updated to
<Chips value={field_managed_by_redux_initial_value} />
Perhaps you don't have the choice and you need to manage a state because of the complexity of react components.
I found a solution for this problem by adding the "componentDidUpdate" method in the Chips Component
Code: Select all
class WorkaroundChips extends Chips {
componentDidUpdate(prevProps, prevState, snapshot) {
if(this.state.values.length !== this.props.value.length) {
this.setState({ values:this.props.value});
}
}
}
Sources:
https://www.reddit.com/r/javascript/com ... n_reactjs/