66 PURLInspectResponse ,
77 VulnInPackage ,
88} from "@/types/api/api" ;
9- import { FunctionComponent , useMemo , useState } from "react" ;
9+ import { FunctionComponent , useMemo } from "react" ;
1010import EcosystemImage from "./common/EcosystemImage" ;
1111import { beautifyPurl , extractVersion } from "@/utils/common" ;
1212import { Badge } from "./ui/badge" ;
@@ -27,7 +27,6 @@ const fetcher = (url: string) => fetch(url).then((res) => res.json());
2727const AffectedComponentDetails : FunctionComponent < {
2828 vuln : DetailedDependencyVulnDTO ;
2929} > = ( { vuln } ) => {
30- const [ activeCVE , setActiveCVE ] = useState < VulnInPackage | null > ( null ) ;
3130 const { theme } = useTheme ( ) ;
3231
3332 const purl = vuln . componentPurl ;
@@ -45,17 +44,13 @@ const AffectedComponentDetails: FunctionComponent<{
4544 revalidateOnReconnect : false ,
4645 } ) ;
4746
48- useSWR ( data ? `matched-cve-${ vuln . cveID } ` : null , ( ) => {
49- if ( data ) {
50- const matchedCVE = data . vulns . find (
51- ( vulnInPkg ) => vuln . cveID === vulnInPkg . CVEID ,
52- ) ;
53- if ( matchedCVE ) {
54- setActiveCVE ( matchedCVE ) ;
55- }
56- }
57- return null ;
58- } ) ;
47+ // Compute the matched CVE from the fetched data
48+ const activeCVE = useMemo ( ( ) => {
49+ if ( ! data ) return null ;
50+ return (
51+ data . vulns . find ( ( vulnInPkg ) => vuln . cveID === vulnInPkg . CVEID ) ?? null
52+ ) ;
53+ } , [ data , vuln . cveID ] ) ;
5954
6055 if ( isLoading ) {
6156 return (
0 commit comments