Instructor: In this lesson, we're going to look at the mdx-deck library to make a slide deck using Markdown and React.
I have an empty directory with no project in it. In order to install mdx-deck, I'll need to make sure I have a package.json file. I can create one by running npm in it or yarn in it. Next, install the library. Do that by saying yarn add mdx-deck.
The next thing I'll need to do is add a script that leverages the mdx-deck CLI to start the deck. The CLI comes baked with hot module replacement for fast updates, React and style components for styling.
Now that we're set up, I'm going to create a deck.mdx file to contain the core of my slide deck. If you haven't heard of an MDX file, it's a magical format that allows you to write Markdown and turn it into a React component. You can check out one of my previous lessons for more info.
The deck.mdx file will contain all of our slides. Let's add the first one. Let's test it out. I'm going to go ahead and start the mdx-deck server and give it a shot. We'll say yarn start.
It looks like it's working. You can see our first slide. Let's go ahead and add another slide. We can do this by adding a horizontal rule or three dashes and adding other slides just by adding more Markup.
I'll add, "This is our second slide." We'll go back to our browser to check it out. There's our first slide and our second slide. That's pretty cool. We can even add code snippets.
I'll add another slide and I'll say jsx, can we say something like button and close it up. Save it, to our browser. There's our third slide. We have a code snippet with button in it.
One of the best things about building your slides with something that leverages React is that we can use React components directly in our slides. I'm going to add a counter component in a new slide to embed it.
One of the coolest features that MDX offers is that you can use ES6 imports directly in your Markdown. I can import my counter as a slide and use it below. Let's test it out. Let's go to the browser, go to my fourth slide. As you can see here, my component is being imported. If I click the button, it works just like a normal React component.
Mdx-deck is very extensible as you can add stuff like new themes. It does come with a couple of themes baked in, and you can enable them by exporting one at the top of your deck file. Dark is looking pretty good. Check out the mdx-deck docs to see how else you can adjust a theme.
The last thing I want to show for this lesson is how to build for production. We'll first need to add another script. Now I can simply run yarn build, and mdx-deck will output two files for us to use in production.