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. 无法解析具体reference那个同名文件

    公司平台,如果src和gen文件系统中有同名文件.reference时会根据depend.cfg文件优先reference遇到的同名文件.这样如果存在同名文件且引用顺序不对就会有莫名的bug. 像rt ...

  2. 设置 TabBarItemt图片颜色

    UIImage *discussSelectedImage = [UIImage imageNamed:@"discuss_selected"];//设置图片不渲染 discuss ...

  3. ARM-Linux基本开发步骤

    拿到一块YC2440(s3c2440)的开发板,经过几天的学习,我对arm-linux系统开发步骤有了一些认识.就以开发这个开发板为例,arm-linux开发工作大概分4个部分 1.       硬件 ...

  4. 03006_Servlet简介

    1.什么是Servlet (1)Servlet 运行在服务端的Java小程序,是sun公司提供一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源: (2)Servlet的实质就是java代码 ...

  5. UI测试点

    UI测试点 1.界面是否美观 2.元素大小 3.界面元素是否对齐方式统一 4.界面字体属性是否正确 5.界面链接及触发动作 6.元素内容是否显示正确.易懂.友好 7.所有输入框进行输入判断测试 8.所 ...

  6. 微软.net一些类的源码

    地址:http://referencesource.microsoft.com/#mscorlib/system/collections/generic/dictionary.cs 关键字:refer ...

  7. SPOJ - ADAQUEUE ,双端队列简单运用!

    ADAQUEUE - Ada and Queue 表示这题是学弟带的榜,题还没看完,学弟吐了一句:这不就是双端队列嘛.于是掏出布满尘埃的<曾粽根ACM程序设计>,嗯,确实是裸题,现学现做. ...

  8. shell的格式化输出命令printf

    printf 命令用于格式化输出, 是echo命令的增强版.它是C语言printf()库函数的一个有限的变形,并且在语法上有些不同. 注意:printf 由 POSIX 标准所定义,移植性要比 ech ...

  9. 【Luogu】P3628特别行动队(斜率优化DP)

    题目链接 设c[i]是战斗力前缀和,f[i]是考虑前i个,且最后一组分到第i个士兵为止的战斗力之和 则有朴素状态转移方程 ;i<=n;++i) ;j<i;++j){ int x=c[i]- ...

  10. HDU 5833 Zhu and 772002 ——线性基

    [题目分析] 这题貌似在UVA上做过,高精度高斯消元. 练习赛T2,然后突然脑洞出来一个用Bitset的方法. 发现代码只需要30多行就A掉了 Bitset大法好 [代码] #include < ...