Skip to content

Commit 200f6ff

Browse files
committedAug 13, 2019
fix: bug when updating value prop to blank
1 parent cba465c commit 200f6ff

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
 

‎src/index.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ export default class EdiText extends Component {
1919
}
2020

2121
componentWillReceiveProps(nextProps) {
22-
if (nextProps.value) {
23-
this.setState({
24-
value: nextProps.value
25-
})
22+
const nextState = {}
23+
if (nextProps.value !== undefined && nextProps.value !== this.state.value) {
24+
nextState.value = nextProps.value;
2625
}
2726

28-
if (nextProps.editing !== undefined) {
29-
this.setState({
30-
editing: nextProps.editing
31-
})
27+
if (nextProps.editing !== undefined && nextProps.editing !== this.state.editing) {
28+
nextState.editing = nextProps.editing;
29+
}
30+
31+
if (Object.keys(nextState).length > 0) {
32+
this.setState(nextState);
3233
}
3334
}
3435

@@ -237,7 +238,7 @@ EdiText.defaultProps = {
237238
type: 'text',
238239
validationMessage: 'Invalid Value',
239240
validation: value => true,
240-
onCancel: () => {},
241+
onCancel: () => { },
241242
cancelButtonContent: '',
242243
saveButtonContent: '',
243244
editButtonContent: '',

0 commit comments

Comments
 (0)