Skip to content

Commit

Permalink
setState only on mounted autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
estambakio-sc committed Apr 24, 2018
1 parent 8668f0b commit 9f72bbd
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AutocompleteContainer extends React.Component {
}

componentDidMount = () => {
this._isMounted = true;
this.searchItems(this.props);
};

Expand All @@ -60,6 +61,10 @@ class AutocompleteContainer extends React.Component {
return !this.state.show || !!this.currEventTarget && this.currEventTarget !== 'widget';
};

componentWillUnmount() {
this._isMounted = false;
}

matchExtension = (extensions, token) => {
for (let i = 0, count = extensions.length; i < count; i++) {
const extension = extensions[i];
Expand Down Expand Up @@ -208,12 +213,12 @@ class AutocompleteContainer extends React.Component {
this.toggleWidget(true);
const request = extension.searchItems(term).
then(items => {
if (this.currentRequest === request) {
if (this.currentRequest === request && this._isMounted) {
this.setState({ items, selectedIndex: 0, loading: false })
}
}).
catch(err => {
if (this.currentRequest === request) {
if (this.currentRequest === request && this._isMounted) {
this.setState({ items: [], loading: false })
}
});
Expand Down

0 comments on commit 9f72bbd

Please sign in to comment.