Browse Source

improve getDerivedStateFromProps return value

pull/13120/head
afc163 6 years ago
parent
commit
c7b9eee709
  1. 3
      components/date-picker/createPicker.tsx
  2. 1
      components/tag/index.tsx
  3. 3
      site/theme/template/Color/ColorPicker.jsx

3
components/date-picker/createPicker.tsx

@ -40,7 +40,6 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
}
if ('value' in nextProps) {
state.value = nextProps.value;
if (
nextProps.value !== prevState.value ||
(!open && nextProps.value !== prevState.showDate)
@ -48,7 +47,7 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
state.showDate = nextProps.value;
}
}
return state;
return Object.keys(state).length > 0 ? state : null;
}
private input: any;

1
components/tag/index.tsx

@ -51,7 +51,6 @@ class Tag extends React.Component<TagProps, TagState> {
closed: !nextProps.visible,
};
}
return newState;
}
return null;

3
site/theme/template/Color/ColorPicker.jsx

@ -16,10 +16,13 @@ export default class ColorPicker extends Component {
}
static getDerivedStateFromProps(props) {
if ('color' in props) {
return {
color: props.color,
};
}
return null;
}
state = {
displayColorPicker: false,

Loading…
Cancel
Save