Embedding an interactive demo
Most posts here are plain text and ship no JavaScript. A post that needs a live demo opts in, and only that post pays for it.
The whole thing is two lines in the MDX file:
import Counter from '../../components/demos/Counter.tsx';
<Counter client:visible />
Picking a client directive
client:visible is the default choice for a demo — the browser loads the
component only when the reader scrolls it into view.
| Directive | Loads when |
|---|---|
client:load |
immediately on page load |
client:idle |
the browser finishes its work |
client:visible |
the element enters the viewport |
client:only |
client side only, never prerendered |
Without a directive the component renders to static HTML and stays inert.
Where demos live
Put them in src/components/demos/. Wrap them in Demo.astro for the framed
box, or drop them straight into the page if the demo brings its own chrome.