Display React functional examples with source code.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
.babelrc.js
.eslintrc.js
.flowconfig
.gitignore
.pr-bumper.json
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
jest.config.js
package.json
yarn.lock

README.md

babel-plugin-react-code-block NPM Coverage

Display React functional examples with source code.

Table of Contents

Installation

npm

npm install babel-plugin-react-code-block

yarn

yarn add babel-plugin-react-code-block

Documentation

Create a code block component with a code property, which will be populated by this plugin:

import React from 'react'

export default ({children, code}) => {
  return (
    <div>
      {children}
      <code>{code}</code>
    </div>
  )
}

Note: In the above example component children is the passed in JSX that you want to render as a demo and code is the passed in JSX converted to a string so you can also print the code sample (which is run through prettier to make it look aesthetically pleasing).

In your Babel configuration include:

module.exports = {
  "plugins": [
    [
      "babel-plugin-react-code-block",
      {
        "component": "CodeBlock",
      },
    ],
  ],
}

Note: In the above configuration change CodeBlock to the name of your code block component. This plugin will simply apply the transform to any JSX elements matching the component name.

Code of Conduct

Please see the code of conduct.

Contributing

Please see the contributing guide.

License

MIT