-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Consider making <> pure unwrapped fragment #11859
Comments
I've stumbled across exactly the same issue. For this to work I now need a render function like this: render() {
const {children} = this.props;
const resolvedChildren =
children.type === Fragment
? children.props.children
: children;
const enhancedChildren = Children.map(resolvedChildren, child =>
React.cloneElement(child, {onClick: this.onClick})
);
render enhancedChildren;
} I'm not sure if that |
As far as I understand, this part should be patched to also consider fragments for this to work: react/packages/react/src/ReactChildren.js Lines 149 to 160 in cc52e06
If that's the case, can I submit a PR? |
My understanding is this was an intentional decision. Paging @acdlite |
Also @clemmy might have context on why this behavior was chosen. |
As you mentioned, the children traversal semantics for In response to @amannn, that patch will change the semantics for both |
I think changing behavior for both might be reasonable. |
I could not find an existing RFC on this subject so I have created one myself |
Feature request
Currently if we pass Fragment with children to any custom component, this component gets that fragment as a child
That means in all components where children is being altered (cloned) we need to check first that each item is a fragment first, and if it is - take its children instead of itself.
This was a little unexpected, because after reading the documentation the impression was that Fragment is a pure abstraction on the caller side, that Fragment doesn't propagate down to components, but only its children.
In the same time it's understandable because Fragment might have more supported props in the future that receiving component might want to read.
But fragment shortcut
<>
will not have props, it will always mean pure abstraction (to group its children to show them by condition, for instance).So maybe react could unwrap its children right away when elements are created and pass them down as set of children (merge with another children on the same level)?
React 16.2
The text was updated successfully, but these errors were encountered: