Skip to content

Commit 4eeb742

Browse files
committed
wrap passed in function with useCallback
1 parent 89e0149 commit 4eeb742

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

x-pack/legacy/plugins/siem/public/pages/network/navigation/network_routes.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React from 'react';
7+
import React, { useCallback } from 'react';
88
import { Route, Switch } from 'react-router-dom';
99
import { EuiFlexItem, EuiSpacer } from '@elastic/eui';
1010

@@ -19,7 +19,7 @@ import { DnsQueryTabBody } from './dns_query_tab_body';
1919
import { ConditionalFlexGroup } from './conditional_flex_group';
2020
import { NetworkRoutesProps, NetworkRouteType } from './types';
2121
import { TlsQueryTabBody } from './tls_query_tab_body';
22-
import { Anomaly, NarrowDateRange } from '../../../components/ml/types';
22+
import { Anomaly } from '../../../components/ml/types';
2323

2424
export const NetworkRoutes = ({
2525
networkPagePath,
@@ -32,17 +32,23 @@ export const NetworkRoutes = ({
3232
setQuery,
3333
setAbsoluteRangeDatePicker,
3434
}: NetworkRoutesProps) => {
35-
const narrowDateRange: NarrowDateRange = (score: Anomaly, interval: string) => {
36-
const fromTo = scoreIntervalToDateTime(score, interval);
37-
setAbsoluteRangeDatePicker({
38-
id: 'global',
39-
from: fromTo.from,
40-
to: fromTo.to,
41-
});
42-
};
43-
const updateDateRange = (min: number, max: number) => {
44-
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
45-
};
35+
const narrowDateRange = useCallback(
36+
(score: Anomaly, interval: string) => {
37+
const fromTo = scoreIntervalToDateTime(score, interval);
38+
setAbsoluteRangeDatePicker({
39+
id: 'global',
40+
from: fromTo.from,
41+
to: fromTo.to,
42+
});
43+
},
44+
[scoreIntervalToDateTime, setAbsoluteRangeDatePicker]
45+
);
46+
const updateDateRange = useCallback(
47+
(min: number, max: number) => {
48+
setAbsoluteRangeDatePicker({ id: 'global', from: min, to: max });
49+
},
50+
[from, to]
51+
);
4652

4753
const tabProps = {
4854
networkPagePath,

0 commit comments

Comments
 (0)