babel-plugin-react-code-block
v0.3.1
Published
Display React functional examples with source code.
Downloads
194
Readme
babel-plugin-react-code-block
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.