Made sure we only resetTypeahead if mounted

This commit is contained in:
Hugo Häggmark
2019-01-28 14:43:59 +01:00
parent edfce0893e
commit dc125f1e4d
+12 -7
View File
@@ -73,6 +73,7 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
placeholdersBuffer: PlaceholdersBuffer; placeholdersBuffer: PlaceholdersBuffer;
plugins: any[]; plugins: any[];
resetTimer: any; resetTimer: any;
mounted: boolean;
constructor(props: QueryFieldProps, context) { constructor(props: QueryFieldProps, context) {
super(props, context); super(props, context);
@@ -93,10 +94,12 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
} }
componentDidMount() { componentDidMount() {
this.mounted = true;
this.updateMenu(); this.updateMenu();
} }
componentWillUnmount() { componentWillUnmount() {
this.mounted = false;
clearTimeout(this.resetTimer); clearTimeout(this.resetTimer);
} }
@@ -347,13 +350,15 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
}; };
resetTypeahead = () => { resetTypeahead = () => {
this.setState({ if (this.mounted) {
suggestions: [], this.setState({
typeaheadIndex: 0, suggestions: [],
typeaheadPrefix: '', typeaheadIndex: 0,
typeaheadContext: null, typeaheadPrefix: '',
}); typeaheadContext: null,
this.resetTimer = null; });
this.resetTimer = null;
}
}; };
handleBlur = () => { handleBlur = () => {