[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高阶组件的一篇文章,看了之后顿时眼前一亮,对于我这种还在新手村晃荡.一切朝着打怪升级看齐的小喽啰来说,像这种难度不是太高同时门槛也不是那么低 ...
随机推荐
- 什么是php?php的优缺点有哪些?与其它编程语言的优缺点?
身为一个PHP开发者,有必要了解一下PHP的缺点,知道每种语言的优点和缺点,才能知道某种语言在什么场景下适合使用,在什么场景下不适合使用. 这个问题我曾经面试的时候遇到过,我之前没总结过,第一问大部分 ...
- 牛客网暑期ACM多校训练营(第六场) C Generation I(组合数学, 逆元)
中链接: https://www.nowcoder.com/acm/contest/144/C 题意: 给定n个集合, 要求用n次操作, 第i次操作用1~m中一个数填入 i ~ n个集合中, 集合无序 ...
- 排序算法C语言实现——冒泡排序
/*冒泡O(n^2)*//*原理: 比较相邻的元素.如果第一个比第二个大,就交换他们两个. 对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应该会是最大的数 ...
- C# 导出Excel的示例
Excel知识点. 一.添加引用和命名空间 添加Microsoft.Office.Interop.Excel引用,它的默认路径是C:\Program Files\Microsoft Visual S ...
- Java-替换字符串中的子字符串
自顶一个repace方法 package com.tj; public class MyClass implements Cloneable { public static void main(Str ...
- Hive中文注释乱码解决方案(2)
本文来自网易云社区 作者:王潘安 执行阶段 launchTask 回到Driver类的runInternal方法,看以下执行过程.在runInternal方法中,执行过程调用了execute方法 ...
- wordpress无法登录的解决方法
使用wordpress建站的朋友可能会遇到wordpress管理密码,有时甚至是正确的密码,但是多次尝试输入都无法登录,并且输入用户名和输入电子邮件都无法获取密码,遇到这种情况怎么办,本文教你如何处理 ...
- Leetcode 363.矩形区域不超过k的最大数值和
矩形区域不超过k的最大数值和 给定一个非空二维矩阵 matrix 和一个整数 k,找到这个矩阵内部不大于 k 的最大矩形和. 示例: 输入: matrix = [[1,0,1],[0,-2,3]], ...
- 【HTML/XML 1】HTML 速成总结
导读:反反复复的看完了HTML的速成材料,前面学习了牛腩,所以这块知识只能是作为一种旧知识的复习.和机房重构时的SQLHelper一样,刚开始都是稀里糊涂的用了,后面系统的学习后,才知道为什么要那样用 ...
- 安卓ImageView.src设置图片拉伸、填满控件的方法
代码改变世界 安卓ImageView.src设置图片拉伸.填满控件的方法 需要给你的ImageView布局加上Android:adjustViewBounds="true"