Skip to content

Commit

Permalink
fix: check whether component is still mounted after timeout
Browse files Browse the repository at this point in the history
fixes #71
  • Loading branch information
ro-ka committed Jan 4, 2016
1 parent 0402b46 commit 67972d0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Geosuggest.jsx
Expand Up @@ -38,6 +38,7 @@ const Geosuggest = React.createClass({
*/
getInitialState: function() {
return {
isMounted: false,
isSuggestsHidden: true,
userInput: this.props.initialValue,
activeSuggest: null,
Expand Down Expand Up @@ -74,6 +75,15 @@ const Geosuggest = React.createClass({

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

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

/**
* When the component will unmount
*/
componentWillUnmount: function() {
this.setState({isMounted: false});
},

/**
Expand Down Expand Up @@ -217,7 +227,9 @@ const Geosuggest = React.createClass({
hideSuggests: function() {
this.props.onBlur();
setTimeout(function() {
this.setState({isSuggestsHidden: true});
if (this.state && this.state.isMounted) {
this.setState({isSuggestsHidden: true});
}
}.bind(this), 100);
},

Expand Down

0 comments on commit 67972d0

Please sign in to comment.