Skip to content

Commit 1ed1b64

Browse files
committed
refactor(EditableTextField): declare nextValue variable
1 parent 3a6dbba commit 1ed1b64

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/common/components/EditableTextField.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ export default class EditableTextField extends Component<Props, State> {
4848

4949
componentWillReceiveProps (nextProps: Props) {
5050
const {initialValue, isEditing, value} = this.state
51-
const valueChanged = this.props.value !== nextProps.value
52-
if (value !== nextProps.value && valueChanged && !isEditing) {
51+
const {value: nextValue} = nextProps
52+
const valueChanged = this.props.value !== nextValue
53+
if (value !== nextValue && valueChanged && !isEditing) {
5354
// Update value if externally changed, but only if the field is not being
5455
// actively edited. This update accounts for cases where the value this
5556
// field represents has been updated (perhaps due to a request to the
5657
// server), but if the user is already editing the field, we don't want to
5758
// interrupt that input.
58-
this.setState({ value: nextProps.value })
59+
this.setState({ value: nextValue })
5960
}
60-
if (initialValue !== nextProps.value) {
61+
if (initialValue !== nextValue) {
6162
// Update initial value if externally changed.
6263
// TODO: investigate whether this conditional case fully accounts for the
6364
// above conditional.
64-
this.setState({ initialValue: nextProps.value })
65+
this.setState({ initialValue: nextValue })
6566
}
6667
}
6768

0 commit comments

Comments
 (0)