MCPcopy Create free account
hub / github.com/danielpetho/fancy / loadSourceCode

Function loadSourceCode

src/components/component-source.tsx:20–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19 React.useEffect(() => {
20 async function loadSourceCode() {
21 try {
22 const mod = await import(`../../public/r/${name}.json`)
23 const json = mod.default
24
25 // Find the main component file that matches the name
26 const mainFile = json.files.find(
27 (file: any) =>
28 file.path
29 .split("/")
30 .pop()
31 .replace(/\.(tsx|ts)$/, "") === name
32 )
33
34 if (mainFile) {
35 setSourceCode(mainFile.content)
36 } else {
37 console.error(`Could not find main file for ${name}`)
38 setSourceCode("")
39 }
40 } catch (error) {
41 console.error(`Failed to load source for ${name}:`, error)
42 setSourceCode("")
43 }
44 }
45 loadSourceCode()
46 }, [name])
47

Callers 1

ComponentSourceFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected