Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Allow children in the props argument of cloneElement #317

Merged
merged 2 commits into from
Mar 7, 2017

Conversation

tkh44
Copy link
Contributor

@tkh44 tkh44 commented Mar 7, 2017

cloneElement - if children are provided in the second
argument of cloneElement they are ignored.

cloneElement(component, { children }) will now properly apply children to component

fixes #316

cloneElement - if children are provided in the second
argument of cloneElement they are ignored.

`cloneElement(component, { children })` will now properly apply children to `component`

fixes preactjs#316
// Only provide the 3rd argument if needed.
// Arguments 3+ overwrite element.children in preactCloneElement
let cloneArgs = [node, props];
if (children && children.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@developit this is the one part I'm not 100% certain on. I'm not sure if I should check children.length here.

Copy link
Member

Choose a reason for hiding this comment

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

I actually wonder (was going to modify and run the tests) if the block on L313 can get dropped? preactCloneElement() will look for props.children if its arity is <=2 and it seems like we're passing it props.children in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You cannot drop the if statement. children will always be an array because of the spread operator. If you provide an empty array to preactCloneElement it will result in the original children being overwritten with [] (nothing).

Use push instead of concat
 - Cleaner
 - Smaller size
@developit developit merged commit c169d38 into preactjs:master Mar 7, 2017
@developit developit added this to the 3.14.0 milestone Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cloneElement - if children are provided in the second argument of cloneElement they are ignored.
2 participants