react-to-jsx

1.3.2 • Public • Published

React to JSX

Generates a JSX string representation of React elements. Takes a React Element (or an array of React Elements). Useful for generating React component style guides.

Usage

Install

npm install react-to-jsx

Basic Usage

var reactToJsx = require('react-to-jsx');
 
var jsxString = reactToJsx(
  <Button
    type="submit"
    size="large">
    Cool Button
  </Button>
);
 
// <Button
//   type="submit"
//   size="large">
//   Cool Button
// </Button>
 
console.log(jsxString);

Options

reactToJsx takes an optional options object: reactToJsx(reactElement, options).

indent

Type: String Default: '\t' (Tab)

Sets the indent string for returned JSX. Should probably match your preferred code style. Two spaces? Four? Three? The choice is yours, friend.

includeNull

Type: 'Boolean' Default: true

Determines whether to include props with a value of null in the returned JSX.

exclude

Type: Array Default: []

Array of props to exclude from the returned JSX. Hide those weird props, they shouldn't be in your docs anyway.

Readme

Keywords

Package Sidebar

Install

npm i react-to-jsx

Weekly Downloads

39,043

Version

1.3.2

License

MIT

Last publish

Collaborators

  • alexlande