This isn't necessarily a bug or a feature, more so asking for why it is implemented as it currently is.
When inside of a component, this.key is undefined, however child.key is defined and has a value within React.Children.map. I realize these point to different instances, just demonstrating the difference.
Example:
class Example extends React.Component {
render() {
console.log(this.key); // undefined
return (
<div>
{React.Children.map(this.props.children, child => {
console.log(child.key); // defined
return child;
})}
</div>
)
}
}
I expect child.key to not be readable/writeable within React.Children.map, however it is both which seems counterintuitive to the idea that this.key is undefined within the component.
This isn't necessarily a bug or a feature, more so asking for why it is implemented as it currently is.
When inside of a component,
this.keyis undefined, howeverchild.keyis defined and has a value withinReact.Children.map. I realize these point to different instances, just demonstrating the difference.Example:
I expect
child.keyto not be readable/writeable withinReact.Children.map, however it is both which seems counterintuitive to the idea thatthis.keyis undefined within the component.