MCPcopy Create free account
hub / github.com/github/docs / ClientSideHighlight

Function ClientSideHighlight

components/ClientSideHighlight.tsx:9–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7})
8
9export function ClientSideHighlight() {
10 const { asPath } = useRouter()
11 // If the page contains `[data-highlight]` blocks, these pages need
12 // syntax highlighting. But not every page needs i t, so it's conditionally
13 // lazy-loaded on the client.
14 const [load, setLoad] = useState(false)
15 useEffect(() => {
16 // It doesn't need to use querySelector because all we care about is if
17 // there is greater than zero of these in the DOM.
18 // Note! This "core selector", which determines whether to bother
19 // or not, needs to match what's used inside ClientSideHighlightJS.tsx
20 if (!load && document.querySelector('[data-highlight]')) {
21 setLoad(true)
22 }
23
24 // Important to depend on the current path because the first page you
25 // load, before any client-side navigation, might not need it, but the
26 // consecutive one does.
27 }, [asPath])
28
29 if (load) return <ClientSideHighlightJS />
30 return null
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected