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

Function ComponentSource

src/components/component-source.tsx:11–49  ·  view source on GitHub ↗
({
  name,
  children,
  className,
  ...props
}: ComponentSourceProps)

Source from the content-addressed store, hash-verified

9}
10
11export function ComponentSource({
12 name,
13 children,
14 className,
15 ...props
16}: ComponentSourceProps) {
17 const [sourceCode, setSourceCode] = React.useState("")
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
48 return <CodeSnippet title={name + ".tsx"} code={sourceCode} language="tsx" />
49}

Callers

nothing calls this directly

Calls 1

loadSourceCodeFunction · 0.70

Tested by

no test coverage detected