Skip to content

Commit

Permalink
fix: remove isMounted antipattern
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
ro-ka committed Mar 11, 2016
1 parent 611fb41 commit b347e9a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Geosuggest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Geosuggest extends React.Component {
constructor(props) {
super(props);
this.state = {
isMounted: false,
isSuggestsHidden: true,
userInput: this.props.initialValue,
activeSuggest: null,
suggests: []
suggests: [],
timer: null
};
}

Expand Down Expand Up @@ -65,15 +65,13 @@ class Geosuggest extends React.Component {

this.autocompleteService = new googleMaps.places.AutocompleteService();
this.geocoder = new googleMaps.Geocoder();

this.setState({isMounted: true});
}

/**
* When the component will unmount
*/
componentWillUnmount() {
this.setState({isMounted: false});
clearTimeout(this.state.timer);
}

/**
Expand Down Expand Up @@ -205,11 +203,11 @@ class Geosuggest extends React.Component {
*/
hideSuggests() {
this.props.onBlur();
setTimeout(() => {
if (this.state && this.state.isMounted) {
this.setState({isSuggestsHidden: true});
}
const timer = setTimeout(() => {
this.setState({isSuggestsHidden: true});
}, 100);

this.setState({timer});
}

/**
Expand Down

0 comments on commit b347e9a

Please sign in to comment.