Skip to content

Commit 3c6719a

Browse files
committed
Update component to be React Strict compatible
1 parent 4b617c9 commit 3c6719a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/Component.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,26 @@ export class DebounceInput extends React.PureComponent {
3939
constructor(props) {
4040
super(props);
4141

42-
this.state = {
43-
value: props.value || ''
44-
};
45-
4642
this.isDebouncing = false;
47-
}
43+
this.state = {value: props.value || ''};
4844

49-
50-
// eslint-disable-next-line react/no-deprecated
51-
componentWillMount() {
5245
const {debounceTimeout} = this.props;
5346
this.createNotifier(debounceTimeout);
5447
}
5548

5649

57-
// eslint-disable-next-line react/no-deprecated
58-
componentWillReceiveProps({value, debounceTimeout}) {
50+
componentDidUpdate(prevProps) {
5951
if (this.isDebouncing) {
6052
return;
6153
}
62-
const {debounceTimeout: oldTimeout} = this.props;
54+
const {value, debounceTimeout} = this.props;
55+
56+
const {debounceTimeout: oldTimeout, value: oldValue} = prevProps;
6357
const {value: stateValue} = this.state;
6458

65-
if (typeof value !== 'undefined' && stateValue !== value) {
59+
if (typeof value !== 'undefined' && oldValue !== value && stateValue !== value) {
60+
// Update state.value if new value passed via props, yep re-render should happen
61+
// eslint-disable-next-line react/no-did-update-set-state
6662
this.setState({value});
6763
}
6864
if (debounceTimeout !== oldTimeout) {

0 commit comments

Comments
 (0)