From 13b7e90dce780426e498bbe9e6e23c3b4f57b82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Mon, 9 Dec 2019 16:33:23 +0100 Subject: [PATCH] Fix conditional hook usage --- .../metrics/components/node_details_page.tsx | 10 ++--- .../infra/public/pages/metrics/index.tsx | 42 ++++++++++--------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/components/node_details_page.tsx b/x-pack/legacy/plugins/infra/public/pages/metrics/components/node_details_page.tsx index cc1f23d676448..933831c6ec87d 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/components/node_details_page.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/metrics/components/node_details_page.tsx @@ -41,7 +41,7 @@ interface Props { isAutoReloading: boolean; refreshInterval: number; sideNav: NavItem[]; - metadata: InfraMetadata | null; + metadata: InfraMetadata; addNavItem(item: NavItem): void; setRefreshInterval(refreshInterval: number): void; setAutoReload(isAutoReloading: boolean): void; @@ -49,10 +49,6 @@ interface Props { setTimeRange(timeRange: MetricsTimeInput): void; } export const NodeDetailsPage = (props: Props) => { - if (!props.metadata) { - return null; - } - const { parsedTimeRange } = props; const { metrics, loading, makeRequest, error } = useNodeDetails( props.requiredMetrics, @@ -65,11 +61,11 @@ export const NodeDetailsPage = (props: Props) => { const refetch = useCallback(() => { makeRequest(); - }, []); + }, [makeRequest]); useEffect(() => { makeRequest(); - }, [parsedTimeRange]); + }, [makeRequest, parsedTimeRange]); if (error) { return ; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx index 93253406aec2d..b330ad02f1022 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx @@ -112,26 +112,28 @@ export const MetricDetail = withMetricPageProviders( })} /> - + {metadata ? ( + + ) : null} )}