Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hacky workaround for getDerivedStateFromProps change in react 16.4 #25142

Merged
merged 3 commits into from
Nov 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ui/public/query_bar/components/query_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare module '@elastic/eui' {
export const EuiOutsideClickDetector: SFC<any>;
}

import { debounce } from 'lodash';
import { debounce, isEqual } from 'lodash';
import React, { Component, SFC } from 'react';
import { getFromLegacyIndexPattern } from 'ui/index_patterns/static_utils';
import { kfetch } from 'ui/kfetch';
Expand Down Expand Up @@ -84,23 +84,30 @@ interface State {
index: number | null;
suggestions: AutocompleteSuggestion[];
suggestionLimit: number;
currentProps?: Props;
}

export class QueryBar extends Component<Props, State> {
public static getDerivedStateFromProps(nextProps: Props, prevState: State) {
if (isEqual(prevState.currentProps, nextProps)) {
return null;
}

if (nextProps.query.query !== prevState.query.query) {
return {
query: {
query: toUser(nextProps.query.query),
language: nextProps.query.language,
},
currentProps: nextProps,
};
} else if (nextProps.query.language !== prevState.query.language) {
return {
query: {
query: '',
language: nextProps.query.language,
},
currentProps: nextProps,
};
}

Expand Down