Universal dependency update tool that fits into your workflows.
 
 
 
 
 
 
Go to file
vvo 1d3407f3ba 3.1.1 2016-07-12 14:57:35 +02:00
.babelrc chore(lint): use new eslint-config-algolia 2016-07-12 14:33:06 +02:00
.eslintignore test(eslint): ignore -dist.js 2015-10-15 23:45:57 +02:00
.eslintrc test(stateless): skip anonymous stateless test 2015-12-09 15:40:54 +01:00
.gitignore chore(git): ignore more files 2015-10-16 21:51:35 +02:00
.travis.yml chore(travis): fix travis) 2016-07-12 14:49:49 +02:00
AnonymousStatelessComponent.js chore(lint): fix linting 2016-02-02 13:54:31 +01:00
CHANGELOG.md 3.1.1 2016-07-12 14:57:35 +02:00
LICENSE First commit 2015-10-15 23:39:27 +02:00
README.md options.showDefaultProps documentation 2016-06-27 15:18:02 -05:00
index-test.js chore(lint): use new eslint-config-algolia 2016-07-12 14:33:06 +02:00
index.js chore(lint): use new eslint-config-algolia 2016-07-12 14:33:06 +02:00
mocha.opts chore(lint): use new eslint-config-algolia 2016-07-12 14:33:06 +02:00
package.json 3.1.1 2016-07-12 14:57:35 +02:00

README.md

react-element-to-jsx-string

Version Build Status License Downloads

Turn a ReactElement into the corresponding JSX string.

Useful for unit testing and any other need you may think of.

Features:

  • supports nesting and deep nesting like <div a={{b: {c: {d: <div />}}}} />
  • props: supports string, number, function (inlined as prop={function noRefCheck() {}}), object, ReactElement (inlined), regex, booleans (with shorthand syntax), ...
  • order props alphabetically
  • sort object keys in a deterministic order (o={{a: 1, b:2}} === o={{b:2, a:1}})
  • handle ref and key attributes, they are always on top of props
  • React's documentation indent style for JSX

Table of Contents generated with DocToc

Setup

npm install react-element-to-jsx-string --save[-dev]

Usage

import React from 'react';
import reactElementToJSXString from 'react-element-to-jsx-string';

console.log(reactElementToJSXString(<div a="1" b="2">Hello, world!</div>));
// <div
//   a="1"
//   b="2"
// >
//   Hello, world!
// </div>

API

reactElementToJSXString(ReactElement[, options])

options.displayName: function(ReactElement)

Provide a different algorithm in charge of finding the right display name (name of the underlying Class) for your element.

Just return the name you want for the provided ReactElement, as a string.

options.showDefaultProps: boolean, default true

If true, default props shown.

If false, default props are omitted unless they differ from from the default value.

Test

npm test
npm run test:watch

Build

npm run build
npm run build:watch

Thanks

alexlande/react-to-jsx was a good source of inspiration.

We built our own module because we had some needs like ordering props in alphabetical order.