Skip to content

Commit

Permalink
fix: Do not use setState to save timer instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
karanjthakkar committed Dec 16, 2016
1 parent 83f57f2 commit 3709fdb
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Geosuggest.jsx
Expand Up @@ -31,8 +31,7 @@ class Geosuggest extends React.Component {
isLoading: false,
userInput: props.initialValue,
activeSuggest: null,
suggests: [],
timer: null
suggests: []
};

this.onInputChange = this.onInputChange.bind(this);
Expand Down Expand Up @@ -85,7 +84,7 @@ class Geosuggest extends React.Component {
* When the component will unmount
*/
componentWillUnmount() {
clearTimeout(this.state.timer);
clearTimeout(this.timer);
}

/**
Expand Down Expand Up @@ -275,14 +274,12 @@ class Geosuggest extends React.Component {
*/
hideSuggests = () => {
this.props.onBlur(this.state.userInput);
const timer = setTimeout(() => {
this.timer = setTimeout(() => {
this.setState({
isSuggestsHidden: true,
activeSuggest: null
});
}, 100);

this.setState({timer});
}

/**
Expand Down

0 comments on commit 3709fdb

Please sign in to comment.