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

Function loadSourceCode

src/components/component-preview.tsx:47–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45
46 React.useEffect(() => {
47 async function loadSourceCode() {
48 try {
49 const mod = await import(`../../public/r/${name}.json`)
50 const json = mod.default
51
52 // Find the main component file that matches the name
53 const mainFile = json.files.find(
54 (file: any) => file.path.split("/").pop().replace(".tsx", "") === name
55 )
56
57 if (mainFile) {
58 setSourceCode(mainFile.content)
59 } else {
60 console.error(`Could not find main file for ${name}`)
61 setSourceCode("")
62 }
63 } catch (error) {
64 console.error(`Failed to load source for ${name}:`, error)
65 setSourceCode("")
66 }
67 }
68 loadSourceCode()
69 }, [name])
70

Callers 1

ComponentPreviewFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected