Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(formatting): render children as function #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adammockor wants to merge 4 commits into algolia:master
base: master
Choose a base branch
Loading
from adammockor:display-children-as-function

Conversation

Copy link

@adammockor adammockor commented Jan 4, 2019
edited
Loading

This is copy paste of #317 since it doesn't get merged due commitlint errors. I fixed that. Thanks @DavidBabel for implementing this. I can provide support to this PR if needed.

DavidBabel reacted with thumbs up emoji
Copy link
Author

I will fix the flow errors. But failing test is not related to this PR and local yarn run test works without error.

Copy link
Contributor

vvo commented Jan 4, 2019

Yep I don't get why it's failing on travis only
image

Copy link
Contributor

vvo commented Jan 4, 2019

cc @Spy-Seth maybe?

Copy link

Do you use the same node version as your travis build ? node_js: node # lastest

Copy link
Collaborator

The ref/key order issue is fixed by #340. You should rebase your PR on top master 😃

Copy link
Collaborator

@armandabric armandabric left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adammockor for this contribution. This feature is really missing in react-element-to-jsx-string

For now, I have some concern about the current proposal to implement it. It's a good start to implement the feature 😺

@@ -71,6 +72,14 @@ const parseReactElement = (
.filter(onlyMeaningfulChildren)
.map(child => parseReactElement(child, options));

if (typeof element.props.children === 'function') {
const functionChildrens = parseReactElement(
element.props.children(),
Copy link
Collaborator

@armandabric armandabric Jan 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about the need to call the children function to be able to format it's result. This could have unwanted side effect in the user land.

For example:

reactElementToJSXString(
 <div>
 {() => {
 console.log('Should not be logged');
 return <div>Hello World</div>;
 }}
 </div>,
 {
 showFunctions: true,
 }
)

adammockor reacted with thumbs up emoji
);
childrens.push(createReactFunctionTreeNode([functionChildrens]));
}

Copy link
Collaborator

@armandabric armandabric Jan 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gotcha with this detection method is is case of mixed children (or multiple function as a children):

// Multiple functions as child
reactElementToJSXString(
 <div>
 {() => <div>Hello Foo</div>}
 {() => <div>Hello Bar</div>}
 </div>,
 {
 showFunctions: true,
 }
)
// Mixed content
reactElementToJSXString(
 <div>
 {() => <div>Hello Foo</div>}
 <span>Some other children</span>
 </div>,
 {
 showFunctions: true,
 }
)

I know this is should not be frequent or maybe event imaginable but the JSX allow it 🤷‍♂️

I do some try with you PR, it's a shame that React.Children filters out the function children. We do not want to re-implement it to be able to conserve function in our parsing.

Copy link
Author

@adammockor adammockor Jan 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and this is related to React.Children behavior.

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

@armandabric armandabric armandabric left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /