In this lesson I demonstrate how to use the library MDXC to create and import React components with Markdown. MDXC converts markdown into JavaScript and supports JSX.

Additional Resources: https://github.com/jamesknelson/mdxc

 
Create a React app by using 'create-react-app':
// .babelrc

{
"presets": ["babel-preset-react-app"]
}

Then, you can import a component from any Markdown file by prepending the filename with !babel-loader!mdx-loader!. For example:

/* eslint-disable import/no-webpack-loader-syntax */
import DocumentComponent from '!babel-loader!mdx-loader!../pages/index.md'

App.js

/* eslint-disable import/no-webpack-loader-syntax */

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css"; import HelloWorld from "!babel-loader!mdx-loader!./HelloWorld.md"; class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<HelloWorld text="blah blah blah" />
</div>
);
}
} export default App;
import Bold from "./Bold"

import Italic from "!babel-loader!mdx-loader!./Italic.md"

prop text

# Heading 

## Heading 

<p>{text}</p>
<Bold>This text is Bold</Bold>
<Italic>This text is Italic</Italic>

Bold.js:

import React from "react";

export default function Bold({ children }) {
return <b>{children}</b>;
}

Italic.md

prop children

{children}

Github

[React] Create and import React components with Markdown using MDXC的更多相关文章

  1. [React] Update State in React with Ramda's Evolve

    In this lesson we'll take a stateful React component and look at how we can refactor our setState ca ...

  2. React报错之React hook 'useState' is called conditionally

    正文从这开始~ 总览 当我们有条件地使用useState钩子时,或者在一个可能有返回值的条件之后,会产生"React hook 'useState' is called conditiona ...

  3. [React] Create & Deploy a Universal React App using Zeit Next

    In this lesson, we'll use next to create a universal React application with no configuration. We'll ...

  4. [React] Create an Animate Content Placeholder for Loading State in React

    We will create animated Content Placeholder as React component just like Facebook has when you load ...

  5. [React] Create component variations in React with styled-components and "extend"

    In this lesson, we extend the styles of a base button component to create multiple variations of but ...

  6. [React Router v4] Render Multiple Components for the Same Route

    React Router v4 allows us to render Routes as components wherever we like in our components. This ca ...

  7. [React] Use the React Effect Hook in Function Components

    Similar to the State Hook, the Effect Hook is “first-class” in React and handy for performing side e ...

  8. React.createClass vs. ES6 Class Components

    1 1 1 https://www.fullstackreact.com/articles/react-create-class-vs-es6-class-components/ React.crea ...

  9. 聊聊React高阶组件(Higher-Order Components)

    使用 react已经有不短的时间了,最近看到关于 react高阶组件的一篇文章,看了之后顿时眼前一亮,对于我这种还在新手村晃荡.一切朝着打怪升级看齐的小喽啰来说,像这种难度不是太高同时门槛也不是那么低 ...

随机推荐

  1. Ubuntu 15.04 Qt5 链接 mysql数据库

    序 最近在Ubuntu15.04下做一个Linux-服务器-客户端通信项目,用到MySQL数据库.开始的时候,在数据库链接时遇到障碍,查找资料解决. 特此记录,分享于此. 环境配置 系统:Ubuntu ...

  2. python中join()函数讲解

    本文简述的是string.join(words[, sep]),它的功能是把字符串或者列表,元组等的元素给连接起来,返回一个字符串,和split()函数与正好相反,看下面的代码理解. a=[" ...

  3. 虚拟机里linux系统安装 CentOS 64-bit(6.4版本)——笔记

    使用的虚拟机是VMware WorkStation 9.0(9.0.0 build-812388) 1. 安装过程中 选择 桥接 此系统可以拥有独立ip.Nat模式跟主机ip一样 2. 安装过程中选择 ...

  4. 浏览器在一次 HTTP 请求中,需要传输一个 4097 字节的文本数据给服务端,可以采用那些方式?

    浏览器在一次 HTTP 请求中,需要传输一个 4097 字节的文本数据给服务端,可以采用那些方式? 存入 IndexdDB 写入 COOKIE 放在 URL 参数 写入 Session 使用 POST ...

  5. luogu2051 [AHOI2009]中国象棋

    巨水,调了好久,心态爆炸 #include <iostream> #include <cstring> #include <cstdio> using namesp ...

  6. 机器学习实战之kNN算法

    机器学习实战这本书是基于python的,如果我们想要完成python开发,那么python的开发环境必不可少: (1)python3.52,64位,这是我用的python版本 (2)numpy 1.1 ...

  7. POJ 1745 Divisibility

    Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9476   Accepted: 3300 Desc ...

  8. BZOJ 3611 [Heoi2014]大工程 ——虚树

    虚树第二题.... 同BZOJ2286 #include <map> #include <cmath> #include <queue> #include < ...

  9. SpringBoot项目整合Druid进行统计监控

    0.druid介绍,参考官网 1.在项目的POM文件中添加alibaba的druid依赖 <dependency> <groupId>com.alibaba</group ...

  10. 【HDOJ5978】To begin or not to begin(概率)

    题意:有k个黑球和1个红球,两个轮流抽,抽到红球算赢,问先手赢的概率大还是后手大还是相等 k<=1e5 思路:手算前几项概率 大胆猜想 #include<cstdio> #inclu ...