Skip to content

Commit fe17748

Browse files
authored
RadioGroup - fix handling of a constant initial value (#1335)
1 parent 446ad5e commit fe17748

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/components/radioButton/RadioGroup.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type RadioGroupProps = ViewProps & {
2222
export type RadioGroupPropTypes = RadioGroupProps; //TODO: remove after ComponentPropTypes deprecation;
2323

2424
interface RadioGroupState {
25+
initialValue?: RadioGroupProps['initialValue'];
2526
value?: RadioGroupProps['initialValue'];
2627
}
2728

@@ -39,28 +40,20 @@ class RadioGroup extends PureComponent<Props, RadioGroupState> {
3940
super(props);
4041

4142
this.state = {
43+
initialValue: props.initialValue,
4244
value: props.initialValue
4345
};
4446
}
4547

46-
static getUpdatedState = (
47-
nextProps: Props,
48-
prevState: RadioGroupState
49-
): RadioGroupState | null => {
50-
const {value} = prevState;
51-
const {initialValue} = nextProps;
52-
53-
if (_.isUndefined(nextProps.initialValue) || value === initialValue) {
54-
return null;
48+
static getDerivedStateFromProps: GetDerivedStateFromProps<Props, RadioGroupState> = (props, state) => {
49+
if (state.initialValue !== props.initialValue) {
50+
return {
51+
initialValue: props.initialValue,
52+
value: props.initialValue
53+
};
5554
}
5655

57-
return {
58-
value: initialValue
59-
};
60-
};
61-
62-
static getDerivedStateFromProps: GetDerivedStateFromProps<Props, RadioGroupState> = (props, state) => {
63-
return RadioGroup.getUpdatedState(props, state);
56+
return null;
6457
}
6558

6659
getContextProviderValue() {

0 commit comments

Comments
 (0)