refactored getDerivedStateFromProps in in-place-edit
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user