My Authors
Read all threads
I'm so glad I used MDX for my blog. It enables things that otherwise would not be possible with Markdown or a CMS, while still being a consumable data source (unlike having the posts be all-JSX)

Some examples in-thread 👇
I created an <Asterisk> component because I wanted to add XKCD-style "jokes on hover". Plus, I tend to be very verbose, and this means I can pack some of that away into an opt-in annotation. MDX code snippet:<br />
<br />
HTML has two image media elements: the international pop-star `img`, and the niche hipster artist `picture`.<Asterisk content=" src="/images/1px.png" data-src="https://pbs.twimg.com/media/EUB9hT9XQAAvvvf.jpg">Screenshot showing an asterisk, with a tooltip showing the contents
For tangential information, I have a `Sidenote` component. It has a `title` prop which accepts JSX, so I can use any special formatting within it. Also a `type` which accepts info/warning/error/success.

So much more flexible than the `<blockquote>` markdown gives you! MDX code:<br />
<br />
<Sidenote<br />
  type= title={
<>
Fancy title with elements!

}
>
Content here!
" src="/images/1px.png" data-src="https://pbs.twimg.com/media/EUB_F39XQAAh18f.jpg">
Example from a blog post showing the Example from a blog post showing the
For code snippets, I built a little playground component on top of react-live. You can pass props using the typical Markdown code-snippet syntax.

Here I specify that it should render a preview (live=true) and that the editor/preview should be equal width (split=[50,50]) MDX code snippet:<br />
<br />
```jsx inline live=true split=[50,50]<br />
<div<br />
  style={{<br />
    '--color-1': 'deepskyblue',<br />
    '--color-2': 'navy',<br />
    background: `<br />
      linear-gradient(<br />
        170deg,<br />
        var(--color-1),<br />
        var(--color-2) 80%<br />
      )<br />
    `,<br />
<br />
    // Unrelated styles:<br />
    color: 'white',<br />
    textAlign: 'center',<br />
    padding: 30,<br />
    borderRadius: 12,<br />
  }}<br />
><br />
  Hello World<br />
</div><br />
```<br />
Screenshot showing a split interface with the same code on the left side, and a blue-gradient button on the right side, centered within an equal-size square.
Because animated GIFs tend to be huge, I use "video GIFs", similar to social media platforms. I created a component for this, and allowed it to support both `light` and `dark` variants, to swap out the src depending on the user's color theme. MDX code:<br />
<br />
<VideoGif<br />
  src={calendarLightFinal}<br />
  darkSrc={calendarDarkFinal}<br />
  caption= />" src="/images/1px.png" data-src="https://pbs.twimg.com/media/EUCBKYFXQAAohwz.jpg">Screenshot of a calendar application in light modeScreenshot of a calendar application in dark mode
The examples I'm showing are JSX-heavy, which might give you the wrong idea. For the most part, my blog posts look like any other Markdown doc.

It's just that when I need something custom, I can pop it in without any fuss =D An example of a section without any JSX:<br />
<br />
### Testing that it works<br />
<br />
The browser devtools will _always think_ that the image has whatever `src` you gave it initially. If you inspect it in the elements pane, you'll see that it uses a `.jpg`.<br />
<br />
To check if it's actually working, the best trick I've found is to right-click and
Having this technology grants power I wouldn't otherwise have. It's not just about a good developer experience, it's about being to deliver next-level user experiences 😌

Blog posts referenced above:
- joshwcomeau.com/performance/em…
- joshwcomeau.com/react/rainbow-…
- joshwcomeau.com/react/persisti…
Important addendum: MDX is a wonderful tool for developer blogs, but it sucks for non-developers. If you're thinking of using it for a site in which non-devs may wish to contribute, please consider an alternative!

I gave a talk about this:
And yeah I didn't mean to say things "weren't possible" with a CMS, you can do a whole lot with a CMS. I give some examples in that talk!

Shouldn't tweet while sleep deprived 😅
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with ✨ Josh ✨

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!