zoukankan      html  css  js  c++  java
  • [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

     
    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 1
    
    ## Heading 2
    
    <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

  • 相关阅读:
    汉化DevExpress
    《苹果往事》的台式翻译
    说说《程序员》杂志的排版
    关于量化考核绩效
    as3 浅复制 深复制
    斜视角的讨论(转)
    斜角地图原理解释及斜角图形绘制实例细述(转)
    垃圾回收测试
    Flash务实主义(八)——减少数据传输量(转)
    翻译]游戏主循环
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9828093.html
Copyright © 2011-2022 走看看