From c7b9eee70921049262d2beee096d75e470eedbd5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 13 Nov 2018 18:03:57 +0800 Subject: [PATCH] :zap: improve getDerivedStateFromProps return value --- components/date-picker/createPicker.tsx | 3 +-- components/tag/index.tsx | 1 - site/theme/template/Color/ColorPicker.jsx | 9 ++++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/date-picker/createPicker.tsx b/components/date-picker/createPicker.tsx index ad5f327737..916ee845ed 100644 --- a/components/date-picker/createPicker.tsx +++ b/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; diff --git a/components/tag/index.tsx b/components/tag/index.tsx index c37c8ede20..a3b9254fb3 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -51,7 +51,6 @@ class Tag extends React.Component { closed: !nextProps.visible, }; } - return newState; } return null; diff --git a/site/theme/template/Color/ColorPicker.jsx b/site/theme/template/Color/ColorPicker.jsx index bd2fad5aee..8e1ce00f68 100644 --- a/site/theme/template/Color/ColorPicker.jsx +++ b/site/theme/template/Color/ColorPicker.jsx @@ -16,9 +16,12 @@ export default class ColorPicker extends Component { } static getDerivedStateFromProps(props) { - return { - color: props.color, - }; + if ('color' in props) { + return { + color: props.color, + }; + } + return null; } state = {