MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / useRelatedPaths

Function useRelatedPaths

app/hooks/useRelatedPaths.ts:6–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { useJsonColumnViewState } from "./useJsonColumnView";
5
6export function useRelatedPaths(): string[] {
7 const cache = useRef(new Map<string, Array<string>>());
8 const { selectedNodeId } = useJsonColumnViewState();
9 const [json] = useJson();
10
11 return useMemo(() => {
12 if (!selectedNodeId) return [];
13
14 //check cache
15 const cachedPaths = cache.current.get(selectedNodeId);
16 if (cachedPaths) {
17 return cachedPaths;
18 }
19
20 //fetch result
21 let paths = getRelatedPathsAtPath(selectedNodeId, json);
22
23 //cache
24 for (let index = 0; index < paths.length; index++) {
25 const path = paths[index];
26 cache.current.set(path, paths);
27 }
28
29 return paths;
30 }, [selectedNodeId, json]);
31}

Callers 1

InfoPanelFunction · 0.90

Calls 3

useJsonColumnViewStateFunction · 0.90
useJsonFunction · 0.90
getRelatedPathsAtPathFunction · 0.90

Tested by

no test coverage detected