-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathindex.js
43 lines (38 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* @flow */
import formatTree from './formatter/formatTree';
import parseReactElement from './parser/parseReactElement';
import type { Element as ReactElement } from 'react';
import type { OptionParams } from './options';
const reactElementToJsxString = (
element: ReactElement<any>,
{
filterProps = [],
showDefaultProps = true,
showFunctions = false,
functionValue,
tabStop = 2,
useBooleanShorthandSyntax = true,
useFragmentShortSyntax = true,
sortProps = true,
maxInlineAttributesLineLength,
displayName,
}: OptionParams = {}
) => {
if (!element) {
throw new Error('react-element-to-jsx-string: Expected a ReactElement');
}
const options = {
filterProps,
showDefaultProps,
showFunctions,
functionValue,
tabStop,
useBooleanShorthandSyntax,
useFragmentShortSyntax,
sortProps,
maxInlineAttributesLineLength,
displayName,
};
return formatTree(parseReactElement(element, options), options);
};
export default reactElementToJsxString;