Write Books in React With Next.js and MDX

Write Books in React With Next.js and MDX

Build your own platform for books in React

With the software in this article, you can load any existing GitBook (popular software for writing books on GitHub) into Next.js and start adding any custom elements you want. Things like:

  • Multiple-choice questions
  • Live code editors
  • Any React component you want!

You can easily build a book with Next.js and MDX, but this is more than a book! It is an extensible educational website (if you aren’t afraid of writing some code). Let’s get into it!

What Is MDX?

MDX is Markdown with JSX. It is a file with both markdown and JSX (React elements) that has an extension .mdx. This is the language I use to write the books. We want to be compatible with existing GitBooks, which are just Markdown, so there is no problem with loading in existing GitBooks.

Keep code and content separate with next-mdx-remote

The GitHub repository for a book should not have any code in it. This gives people the impression that your book is some new code base to learn when it should just be a bunch of plain text files.

To separate our content from our code, we use a library called next-mdx-remote and grab code using a request to raw.githubusercontent like so:

import renderToString from "next-mdx-remote/render-to-string";
import axios from 'axios'
source = await(await axios.get("https://raw.githubusercontent.com//Open-EdTech/next-mdx-books/main/DOCS/generate.md")).data;
const mdxSource = await renderToString(source);

nextjs programming react javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

Learn React and JavaScript Programming Basics with Example Code

Learn React and JavaScript Programming Basics with Example Code. How does modern JavaScript knowledge make you an efficient React developer? What kind of changes do you need in your mindset when you design and develop a React application? How to Use Let and Const in JavaScript. How to Use Template Literals in JavaScript. How to Import and Export Modules in JavaScript. How to Use Arrow Functions in JavaScript. How Destructuring Works in JavaScript. How the Spread Operator and Rest Parameter Work in JavaScript. How to Use Classes in JavaScript

React cloneElement: A Better Way to Build a Component API Props in ES6 Javascript and Ts

Using the React cloneElement is a better way to build a component API props in ES6 Javascript and Typescript. Here's a tutorial on how to do so.

Qual a relação entre Java e JavaScript, C e C++, React e React Native

Qual a relação entre Java e JavaScript, C e C++, React e React Native