diff --git a/src/Form/RadioGroup.js b/src/Form/RadioGroup.js index 1830003..89decd1 100644 --- a/src/Form/RadioGroup.js +++ b/src/Form/RadioGroup.js @@ -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;