r/reactjs • u/shakya47 • 9h ago
Show /r/reactjs I built unfold-mdx: step-by-step tutorials where each click highlights what changed in the explanation and the code
Demo GIF is at the top of the README: https://github.com/Shakya47/unfold-mdx
When I read code tutorials, I spend half my attention diffing step 3 against step 2 in my head. So I built a small React component for MDX/React docs that does that part.
How it works: you write each step as a full snapshot (the whole explanation so far and the whole code so far). unfold-mdx diffs consecutive snapshots and, on every Next click, highlights the new or changed sentences and the new or changed code lines/tokens.
<Depth>
<DepthLevel label="Check the cache">Look for the product in the cache.</DepthLevel>
<DepthCode lang="js">{`const cached = await cache.get(id);`}</DepthCode>
<DepthLevel label="Return on a hit">
Look for the product in the cache. Return immediately if it is there.
</DepthLevel>
<DepthCode lang="js">{`const cached = await cache.get(id);
if (cached) return cached;`}</DepthCode>
</Depth>What's in 0.1.0
- Prose + code side by side or stacked, with a resizable divider
- Optional Shiki syntax highlighting
- Step-synced highlights on images, screenshots and Mermaid/SVG diagrams
- Grid layouts with custom slots; build your own controls with
useDepth() - Headless (
data-*attributes) with an optional theme; SSR fallback and keyboard navigation - Ships
llms.txtso an AI coding agent can write walkthroughs in the right format
Honest limitations: it's pre-1.0, so the API may still change. Prose has to be plain sentences (that's what gets diffed), and the Shiki adapter currently targets Shiki v1.
- Live demos: https://shakya47.github.io/unfold-mdx/
- GitHub: https://github.com/Shakya47/unfold-mdx
- npm:
npm i @unfold-mdx/react
I'd love feedback, especially: would you use full snapshots like this, or would you rather write only the change for each step?
1
u/Salkinator 2h ago
Very cool. Definitely can think of some good use cases. Just curious (no shade) did you leverage AI when building this? I’m interested in seeing how and where you’ve leveraged it