mirror of https://github.com/renovatebot/renovate
azure-devopsbitbucketdependenciesdependencies-checkingdependency-managergithubgitlabhacktoberfesthacktoberfest-acceptednpmpackage-management
873c2f6ec0 | ||
---|---|---|
.eslintignore | ||
.eslintrc | ||
.gitignore | ||
.npmignore | ||
.travis.yml | ||
CHANGELOG.md | ||
LICENSE | ||
README.md | ||
index-test.js | ||
index.js | ||
mocha.opts | ||
npm-shrinkwrap.json | ||
package.json |
README.md
react-element-to-jsx-string
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}}
) - handle
ref
andkey
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>
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.