MCPcopy Index your code
hub / github.com/simstudioai/sim / usePrism

Function usePrism

packages/emcn/src/components/code/code.tsx:65–80  ·  view source on GitHub ↗

* Subscribes a client component to the lazily-loaded Prism module. * * Seeds from resolvedPrism so viewers mounted after the first load * highlight synchronously; otherwise returns `null` until Prism resolves (so * callers render the plaintext fallback), then the loaded module. * * @re

()

Source from the content-addressed store, hash-verified

63 * @returns The loaded Prism module, or `null` while loading.
64 */
65function usePrism(): PrismModule | null {
66 const [prism, setPrism] = useState<PrismModule | null>(resolvedPrism)
67
68 useEffect(() => {
69 if (prism) return
70 let active = true
71 loadPrism().then((mod) => {
72 if (active) setPrism(mod)
73 })
74 return () => {
75 active = false
76 }
77 }, [prism])
78
79 return prism
80}
81
82/**
83 * Escapes HTML special characters so raw code can be safely injected via

Callers 1

code.tsxFile · 0.85

Calls 1

loadPrismFunction · 0.85

Tested by

no test coverage detected