Socket
Socket
Sign inDemoInstall

babel-plugin-react-element-to-jsx-string

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-element-to-jsx-string

Turn a ReactElement into the corresponding JSX string at build time.


Version published
Weekly downloads
27
decreased by-50.91%
Maintainers
1
Weekly downloads
 
Created
Source
Last npm Registry Version Build Status Code coverage

babel-plugin-react-element-to-jsx-string

Turn a ReactElement into the corresponding JSX string at build time.

Table of Contents

Example

Mark your React Component with the comment /* react-element-to-jsx-string */:

import React from 'react';

/* react-element-to-jsx-string */
const Article = ({ title, content }) => (
  <article>
    <h1>{title}</h1>
    <p>{content}</p>
  </article>
);

export default Article;

And the JSX as string will be added next to your React Component:

import React from 'react';

/* react-element-to-jsx-string */
const Article = ({ title, content }) => (
  <article>
    <h1>{title}</h1>
    <p>{content}</p>
  </article>
);
Article.jsxString = "<article>\n  <h1>{title}</h1>\n  <p>{content}</p>\n</article>";

export default Article;

Install

Node.js v8 or newer is required.

Via the yarn client:

$ yarn add --dev babel-plugin-react-element-to-jsx-string

Via the npm client:

$ npm install --save-dev babel-plugin-react-element-to-jsx-string

Usage

  1. Add to your babel config this plugin:
{
  "plugins": ["babel-plugin-react-element-to-jsx-string"]
}
  1. Add before a React Component a comment with /* react-element-to-jsx-string */, and the first JSX code will be added as string in a property called jsxString.

  2. What about changing the default property name? That can be done in two ways:

  • Via the flag comment:
/* react-element-to-jsx-string: fooBar */
  • Via the plugin options:
{
  "plugins": [["babel-plugin-react-element-to-jsx-string", { "id": "fooBar" }]]
}

Contribute

Feel free to dive in! Open an issue or submit PRs.

babel-plugin-react-element-to-jsx-string follows the Contributor Covenant Code of Conduct.

License

MIT

Keywords

FAQs

Package last updated on 08 Oct 2018

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