diff --git a/app/hooks/useRelatedPaths.ts b/app/hooks/useRelatedPaths.ts index ef1c371..3aa14f6 100644 --- a/app/hooks/useRelatedPaths.ts +++ b/app/hooks/useRelatedPaths.ts @@ -4,7 +4,7 @@ import { useJson } from "./useJson"; import { useJsonColumnViewState } from "./useJsonColumnView"; export function useRelatedPaths(): string[] { - const cache = useRef({}); + const cache = useRef(new Map>()); const { selectedNodeId } = useJsonColumnViewState(); const [json] = useJson(); @@ -12,7 +12,7 @@ export function useRelatedPaths(): string[] { if (!selectedNodeId) return []; //check cache - const cachedPaths = cache.current[selectedNodeId]; + const cachedPaths = cache.current.get(selectedNodeId); if (cachedPaths) { return cachedPaths; } @@ -23,13 +23,9 @@ export function useRelatedPaths(): string[] { //cache for (let index = 0; index < paths.length; index++) { const path = paths[index]; - cache.current[path] = paths; + cache.current.set(path, paths); } return paths; }, [selectedNodeId, json]); } - -type RelatedPathCache = { - [index: string]: Array; -};