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. docker 运行tomcat 并部署 java web项目

    以下tomcat官方镜像中tomcat:7 和tomcat:8的目录. CATALINA_BASE: /usr/local/tomcat CATALINA_HOME: /usr/local/tomca ...

  2. day18-python之迭代器和生成器

    1.文件处理模式b模式 #!/usr/bin/env python # -*- coding:utf-8 -*- # f=open('test.py','rb',encoding='utf-8') # ...

  3. Struts2之初体验

    Struts21.了解Struts2 请求调度框架Struts2是一个MVC框架Struts2类库:Struts2-core Struts2核心XWork-core xwork核心 Struts2的构 ...

  4. php expat+DOM+SimpleXML XML读取

    XML 文件 将在我们的例子中使用下面的 XML 文件: <?xml version="1.0" encoding="ISO-8859-1"?> & ...

  5. xshell连接linux

    一些命令和快捷键: Ctrl + Alt 切换linux和windows的鼠标 Ctrl + c 或 Ctrl + d退出>状态 在xshell终端输入exit,退出与linux服务器的连接 登 ...

  6. tomcat 下catalina.out 日志乱码问题处理

    问题: 项目部署到Linux服务器之后,控制台 catalina.out 文件输出的中文为乱码: 解决办法: 方法一:修改tomcat下的模板编码 bin/catalina.sh 文件添加如下配置:J ...

  7. js中取绝对值的2种方法!

    1.abs() var aaa=-20; var bbb=Math.abs(aaa); 2.加减法 var aaa=-20; var bbb=-aaa

  8. 九度oj 题目1337:寻找最长合法括号序列

    题目描述: 给你一个长度为N的,由’(‘和’)’组成的括号序列,你能找出这个序列中最长的合法括号子序列么?合法括号序列的含义便是,在这个序列中,所有的左括号都有唯一的右括号匹配:所有的右括号都有唯一的 ...

  9. tomcat的安装和优化

    tomcat的安装 jdk版本安装 #!/bin/bash # desc: jdk安装脚本1. 1.7 1.8 download_url='http://**************' jdk_env ...

  10. 【Luogu】P2220容易题(快速幂)

    这题真是“容易”.呵呵呵. 参考题解:xyz32768 代码 #include<cstdio> #include<map> #include<algorithm> ...