Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@ let Basic = React.createClass({
console.log(jsxToString(<Basic test1="ignore" />, {
displayName: 'CustomName'
})); //outputs: <CustomName />
```

* singleLineProps (boolean)

Optional. Defaults to false. Prints props on a single line when the component has children.

```js
import React from 'react';
import jsxToString from 'jsx-to-string';
//or var jsxToString = require('jsx-to-string');

let Basic = React.createClass({
render() {
return (
<div />
);
}
}); //this is your react component

console.log(jsxToString(<Basic test1="prop1" test2="prop2">child</Basic>, {
singleLineProps: true
}));
//outputs:
//<Basic test1='prop1' test2='prop2'>
// child
//</Basic>
```

### License
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function jsxToString (component, options) {
ignoreTags: [],
keyValueOverride: {},
spacing: 0,
detectFunctions: false
detectFunctions: false,
singleLineProps: false
};

const opts = {...baseOpts, ...options};
Expand Down Expand Up @@ -120,7 +121,7 @@ function jsxToString (component, options) {
value = valueLines.join(`\n${indentation}`);
}
return `${key}=${value}`;
}).join(`\n${indentation}`);
}).join(opts.singleLineProps ? ' ' : `\n${indentation}`);

if (component.key && opts.ignoreProps.indexOf('key') === -1) {
componentData.props += `key='${component.key}'`;
Expand Down