mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-05 03:12:14 +00:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { useMountEffect } from "@/hooks/use-mount-effect";
|
|
import { useLighthouseContextStore } from "@/store/lighthouse-context/store";
|
|
import type { LighthouseContextItem } from "@/types/lighthouse-context";
|
|
|
|
interface LighthouseContextContributorProps {
|
|
contributorId: string;
|
|
item: LighthouseContextItem;
|
|
}
|
|
|
|
export function LighthouseContextContributor({
|
|
contributorId,
|
|
item,
|
|
}: LighthouseContextContributorProps) {
|
|
return (
|
|
<MountedLighthouseContextContributor
|
|
key={`${contributorId}:${JSON.stringify(item)}`}
|
|
contributorId={contributorId}
|
|
item={item}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function MountedLighthouseContextContributor({
|
|
contributorId,
|
|
item,
|
|
}: LighthouseContextContributorProps) {
|
|
const registerContribution = useLighthouseContextStore(
|
|
(state) => state.registerContribution,
|
|
);
|
|
const removeContribution = useLighthouseContextStore(
|
|
(state) => state.removeContribution,
|
|
);
|
|
|
|
// The wrapper keys this mounted registration by its bounded snapshot. New
|
|
// server or interactive data therefore replaces stale context without a
|
|
// direct dependency-driven useEffect.
|
|
useMountEffect(() => {
|
|
registerContribution(contributorId, item);
|
|
return () => removeContribution(contributorId);
|
|
});
|
|
|
|
return null;
|
|
}
|