Skip to content

Commit 05e953f

Browse files
authored
Merge pull request #115 from packetloop/React-Strict
React.Strict compatibility
2 parents 4b617c9 + 7a44186 commit 05e953f

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

example/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ const appRoot = document.createElement('div');
99

1010
appRoot.id = 'app';
1111
document.body.appendChild(appRoot);
12-
ReactDOM.render(<App />, appRoot);
12+
ReactDOM.render(<React.StrictMode><App /></React.StrictMode>, appRoot);

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)