index.js.flow 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* @flow */
  2. import formatTree from './formatter/formatTree';
  3. import parseReactElement from './parser/parseReactElement';
  4. import type { Element as ReactElement } from 'react';
  5. import type { Options } from './options';
  6. const reactElementToJsxString = (
  7. element: ReactElement<any>,
  8. {
  9. filterProps = [],
  10. showDefaultProps = true,
  11. showFunctions = false,
  12. functionValue,
  13. tabStop = 2,
  14. useBooleanShorthandSyntax = true,
  15. useFragmentShortSyntax = true,
  16. sortProps = true,
  17. maxInlineAttributesLineLength,
  18. displayName,
  19. }: Options = {}
  20. ) => {
  21. if (!element) {
  22. throw new Error('react-element-to-jsx-string: Expected a ReactElement');
  23. }
  24. const options = {
  25. filterProps,
  26. showDefaultProps,
  27. showFunctions,
  28. functionValue,
  29. tabStop,
  30. useBooleanShorthandSyntax,
  31. useFragmentShortSyntax,
  32. sortProps,
  33. maxInlineAttributesLineLength,
  34. displayName,
  35. };
  36. return formatTree(parseReactElement(element, options), options);
  37. };
  38. export default reactElementToJsxString;
  39. export {
  40. inlineFunction,
  41. preserveFunctionLineBreak,
  42. } from './formatter/formatFunction';