Skip to content

Commit 847897b

Browse files
committed
memoize calls
1 parent c147efc commit 847897b

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

apps/site/components/EOL/EOLModal/index.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Modal, Title, Content } from '@node-core/ui-components/Common/Modal';
22
import { useTranslations } from 'next-intl';
3-
import type { FC } from 'react';
3+
import { useMemo, type FC } from 'react';
44

55
import UnknownSeveritySection from '#site/components/EOL/UnknownSeveritySection';
66
import VulnerabilitiesTable from '#site/components/EOL/VulnerabilitiesTable';
@@ -26,21 +26,33 @@ const EOLModal: FC<ModalProps> = ({ open, closeModal, data }) => {
2626
}
2727
);
2828

29-
const [knownVulnerabilities, unknownVulnerabilities] = vulnerabilities.reduce(
30-
(acc, vulnerability) => {
31-
if (vulnerability.severity === 'unknown') {
32-
acc[1].push(vulnerability as UnknownSeverityVulnerability);
33-
} else {
34-
acc[0].push(vulnerability as KnownVulnerability);
35-
}
36-
return acc;
37-
},
38-
[[], []] as [Array<KnownVulnerability>, Array<UnknownSeverityVulnerability>]
29+
const [knownVulnerabilities, unknownVulnerabilities] = useMemo(
30+
() =>
31+
vulnerabilities.reduce(
32+
(acc, vulnerability) => {
33+
if (vulnerability.severity === 'unknown') {
34+
acc[1].push(vulnerability as UnknownSeverityVulnerability);
35+
} else {
36+
acc[0].push(vulnerability as KnownVulnerability);
37+
}
38+
return acc;
39+
},
40+
[[], []] as [
41+
Array<KnownVulnerability>,
42+
Array<UnknownSeverityVulnerability>,
43+
]
44+
),
45+
[vulnerabilities]
3946
);
4047

41-
knownVulnerabilities.sort(
42-
(a, b) =>
43-
SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity)
48+
useMemo(
49+
() =>
50+
knownVulnerabilities.sort(
51+
(a, b) =>
52+
SEVERITY_ORDER.indexOf(a.severity) -
53+
SEVERITY_ORDER.indexOf(b.severity)
54+
),
55+
[knownVulnerabilities]
4456
);
4557

4658
const hasKnownVulnerabilities = knownVulnerabilities.length > 0;

0 commit comments

Comments
 (0)