Skip to content

Commit

Permalink
[ML] AIOps: Replace useMount with useEffect to consider return cleanu…
Browse files Browse the repository at this point in the history
…p callback. (#148229)

Replace `useMount` (just the usages with return callbacks) with
`useEffect` to consider return cleanup callback.
  • Loading branch information
walterra authored Jan 3, 2023
1 parent 1c3dc4a commit 9111a2e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import React, {
} from 'react';
import { type DataViewField } from '@kbn/data-views-plugin/public';
import { startWith } from 'rxjs';
import useMount from 'react-use/lib/useMount';
import type { Query, Filter } from '@kbn/es-query';
import { usePageUrlState } from '@kbn/ml-url-state';
import {
Expand Down Expand Up @@ -129,7 +128,7 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {

const timeRange = useTimeRangeUpdates();

useMount(function updateIntervalOnTimeBoundsChange() {
useEffect(function updateIntervalOnTimeBoundsChange() {
const timeUpdateSubscription = timefilter
.getTimeUpdate$()
.pipe(startWith(timefilter.getTime()))
Expand All @@ -145,7 +144,8 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {
return () => {
timeUpdateSubscription.unsubscribe();
};
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const metricFieldOptions = useMemo<DataViewField[]>(() => {
return dataView.fields.filter(({ aggregatable, type }) => aggregatable && type === 'number');
Expand Down Expand Up @@ -195,15 +195,16 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {
[filterManager]
);

useMount(() => {
useEffect(() => {
setResultFilter(filterManager.getFilters());
const sub = filterManager.getUpdates$().subscribe(() => {
setResultFilter(filterManager.getFilters());
});
return () => {
sub.unsubscribe();
};
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(
function syncFilters() {
Expand Down

0 comments on commit 9111a2e

Please sign in to comment.