react-element-to-jsx-string icon indicating copy to clipboard operation
react-element-to-jsx-string copied to clipboard

Support Render Functions (`children` being a function)

Open daedalus28 opened this issue 6 years ago • 5 comments

Right now, react-element-to-jsx-string seems to ignore function children. With the new context API using a function for children, this is extra important.

daedalus28 avatar Jun 08 '18 18:06 daedalus28

Dupe of #63

pascalduez avatar Jun 09 '18 05:06 pascalduez

There's a number of different patterns for overloading children outlined in this article: https://medium.com/@martin_hotell/react-children-composition-patterns-with-typescript-56dfc8923c64

I'm using the 2nd one (named slot projection), and this also kills react-element-to-jsx-string:

Uncaught Error: react-element-to-jsx-string: Expected a React.Element, got `object`
    at parseReactElement (parseReactElement.js:51)

ProdigySim avatar Aug 17 '18 17:08 ProdigySim

Any news for this issue ?

This missing feature make the lib kind of useless for newGen React.

DavidBabel avatar Oct 23 '18 16:10 DavidBabel

This PR is a first approach to fix the issue : https://github.com/algolia/react-element-to-jsx-string/pull/317

In my case it solve completely my problem.

DavidBabel avatar Oct 24 '18 12:10 DavidBabel

Cannot really confirm that it solved for me. Otherwise really great lib, worked the best so far.

My code:

<Dropdown>
  {({ handleClose }) => (
    <>
      <DropdownItem>Item 1</DropdownItem>
      <DropdownItem onClick={handleClose}>Item 2 with close</DropdownItem>
    </>
  )}
</Dropdown>

Result

<Dropdown />

Options

    showDefaultProps: false,
    showFunctions: true,
    maxInlineAttributesLineLength: 100,

Cheers guys

march08 avatar May 15 '19 08:05 march08