Universal dependency update tool that fits into your workflows.
 
 
 
 
 
 
Go to file
vvo ce7b89e904 2.0.5 2015-10-21 11:36:09 +02:00
.eslintignore test(eslint): ignore -dist.js 2015-10-15 23:45:57 +02:00
.eslintrc First commit 2015-10-15 23:39:27 +02:00
.gitignore chore(git): ignore more files 2015-10-16 21:51:35 +02:00
.npmignore chore(build): add full shrinkwrap 2015-10-15 23:46:06 +02:00
.travis.yml test(ci): do check shrinkwrap in test 2015-10-16 12:23:43 +02:00
CHANGELOG.md 2.0.5 2015-10-21 11:36:09 +02:00
LICENSE First commit 2015-10-15 23:39:27 +02:00
README.md docs(readme): move TOC lower 2015-10-16 18:21:51 +02:00
index-test.js fix: merge plain strings props replacements 2015-10-21 11:34:32 +02:00
index.js fix: merge plain strings props replacements 2015-10-21 11:34:32 +02:00
mocha.opts First commit 2015-10-15 23:39:27 +02:00
npm-shrinkwrap.json 2.0.5 2015-10-21 11:36:09 +02:00
package.json 2.0.5 2015-10-21 11:36:09 +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..
  • order props alphabetically
  • sort object keys in a deterministic order (o={{a: 1, b:2}} === o={{b:2, a:1}})
  • 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>

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.