Answer the question
In order to leave comments, you need to log in
Is accessing a child property in the render method a daily practice?
Is it a practice to access child properties in the render method?
class CustomComponent extends Component {
handler(){
}
render(){
this.props.children.onClick = handler;
return (
<div>{this.props.children}</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
No. And in general, this is not very good - because. the properties of child components must be encapsulated (the component only works with its own properties). But sometimes it is appropriate - for example, I wrote a small library the other day and something similar was part of a hidden api. Route configuration in React Router is done the same way. But I definitely don't recommend using it universally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question