[React] Create and import React components with Markdown using MDXC
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
// .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}
[React] Create and import React components with Markdown using MDXC的更多相关文章
- [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 ...
- React报错之React hook 'useState' is called conditionally
正文从这开始~ 总览 当我们有条件地使用useState钩子时,或者在一个可能有返回值的条件之后,会产生"React hook 'useState' is called conditiona ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- React.createClass vs. ES6 Class Components
1 1 1 https://www.fullstackreact.com/articles/react-create-class-vs-es6-class-components/ React.crea ...
- 聊聊React高阶组件(Higher-Order Components)
使用 react已经有不短的时间了,最近看到关于 react高阶组件的一篇文章,看了之后顿时眼前一亮,对于我这种还在新手村晃荡.一切朝着打怪升级看齐的小喽啰来说,像这种难度不是太高同时门槛也不是那么低 ...
随机推荐
- linux下如何编译运行c程序
GCC是Linux操作系统下一个非常重要的源代码编译工具,有着许多重要的选项,支持许多不同语言的编译,如C.C++.Ada.Fortran.Objective.Perl.Python.Ruby以及Ja ...
- BZOJ 2295: [POJ Challenge]我爱你啊
由于是子序列,那么难度就在于读入 #include<cstdio> #include<algorithm> #include<cstring> using name ...
- 关于在一台主机上安装2个不同版本的Oracle服务端
一.安装Oracle12c 按正常安装方法安装即可! ORACLE_BASE=/u01/app ORACLE_HOME=/u01/app/oracle ORACLE_SID=a4orcl 二.安装Or ...
- AWK原理及命令和文件输入
一.awk简介 1.awk是3个姓氏的首字母,代表该语言的3个作者,awk的版本有很多,包括:旧版awk,新版awk(nawk),GNU awk(gawk)等. awk程序有awk命令,括在引 ...
- python基础-对象
1. 对象:一组数据和操作数据方法的集合 >>> class Person(object): ... def __init__(self,name): ... ...
- OSPF 提升四 Network Types & FRAM-RELAY
Network Types 1.loopback 2.point-to-point 3.broadcast 4.NBMA 5.POINT-TO-Multipoint 6.point-To-Multip ...
- 01-封装函数求斐波那契数列第n项
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Android Email check 正则表达式
Android Email check 正则表达式 (?:[-!#-\\'*+\\x2f-9=?A-Z^-~]+(?:\\.[-!#-\\'*+\\x2f-9=?A-Z^-~]+)*|\"( ...
- 【Luogu】P2016战略游戏(树形DP)
题目链接 设f[i][j]表示以节点i为根的子树在状态j的情况下的最优解. j有两种情况. j=1:i这个根节点有士兵在站岗. j=0:i这个根节点没有士兵在站岗. 转移方程很好想. f[x][]+= ...
- BZOJ 4568 [Scoi2016]幸运数字 ——线性基 倍增
[题目分析] 考虑异或的最大值,维护线性基就可以了. 但是有多次的询问,树剖或者倍增都可以. 想了想树剖动辄数百行的代码. 算了,我还是写倍增吧. 注:被位运算和大于号的优先级坑了一次,QaQ [代码 ...