Skip to content

Support Render Functions (children being a function) #295

Open
@daedalus28

Description

@daedalus28

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.

Activity

pascalduez

pascalduez commented on Jun 9, 2018

@pascalduez
Contributor

Dupe of #63

ProdigySim

ProdigySim commented on Aug 17, 2018

@ProdigySim

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)
DavidBabel

DavidBabel commented on Oct 23, 2018

@DavidBabel

Any news for this issue ?

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

DavidBabel

DavidBabel commented on Oct 24, 2018

@DavidBabel

This PR is a first approach to fix the issue : #317

In my case it solve completely my problem.

march08

march08 commented on May 15, 2019

@march08

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pascalduez@ProdigySim@daedalus28@DavidBabel@march08

        Issue actions

          Support Render Functions (`children` being a function) · Issue #295 · algolia/react-element-to-jsx-string