Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-react-code-block

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-code-block

Display React functional examples with source code.

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-46.3%
Maintainers
2
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 10 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc