Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
fix(RadioGroup): don't loop state updates
Browse files Browse the repository at this point in the history
  • Loading branch information
choochootrain committed Dec 1, 2018
1 parent ff0f468 commit 7114cea
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Form/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ export default class RadioGroup extends Component {
size: 'md',
};

state = {
value: this.props.value || null,
};
static getDerivedStateFromProps(props, state) {
if (props.value === state.value) {
return null;
}

componentDidUpdate() {
if (this.props.value !== undefined && this.props.value !== this.state.value) {
this.handleChange(null, this.props.value);
return {
value: props.value,
}
}

state = {
value: this.props.value || null,
};

handleChange = (field, value) => {
// Bail out if value is the same
if (this.state.value === value) return;
Expand Down

0 comments on commit 7114cea

Please sign in to comment.