refactored getDerivedStateFromProps in in-place-edit

This commit is contained in:
or-else
2019-08-15 10:49:24 +03:00
parent 0217d84721
commit fb9461834a
+7 -7
View File
@@ -21,16 +21,16 @@ export default class InPlaceEdit extends React.Component {
this.handlePasswordFinished = this.handlePasswordFinished.bind(this); this.handlePasswordFinished = this.handlePasswordFinished.bind(this);
} }
static getDerivedStateFromProps(nextProps, prevState) { componentDidUpdate(prevProps, prevState) {
// If text has changed while in read mode, update text and discard changes. // If text has changed while in read mode, update text and discard changes.
// Ignore update if in edit mode. // Ignore update if in edit mode.
if (prevState.initialValue != nextProps.value && !prevState.active) { const newValue = this.props.value || '';
return { if (prevState.initialValue != newValue && !prevState.active) {
initialValue: nextProps.value || '', this.setState({
value: nextProps.value || '' initialValue: newValue,
}; value: newValue
});
} }
return null;
} }
handeTextChange(e) { handeTextChange(e) {