Skip to content

Commit

Permalink
Update component to be React Strict compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
nkbt committed Oct 17, 2019
1 parent 4b617c9 commit 3c6719a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@ export class DebounceInput extends React.PureComponent {
constructor(props) {
super(props);

this.state = {
value: props.value || ''
};

this.isDebouncing = false;
}
this.state = {value: props.value || ''};


// eslint-disable-next-line react/no-deprecated
componentWillMount() {
const {debounceTimeout} = this.props;
this.createNotifier(debounceTimeout);
}


// eslint-disable-next-line react/no-deprecated
componentWillReceiveProps({value, debounceTimeout}) {
componentDidUpdate(prevProps) {
if (this.isDebouncing) {
return;
}
const {debounceTimeout: oldTimeout} = this.props;
const {value, debounceTimeout} = this.props;

const {debounceTimeout: oldTimeout, value: oldValue} = prevProps;
const {value: stateValue} = this.state;

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

0 comments on commit 3c6719a

Please sign in to comment.