C
C
copal2016-03-31 17:17:22
React
copal, 2016-03-31 17:17:22

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

1 answer(s)
N
Nikita Gushchin, 2016-03-31
@copal

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 question

Ask a Question

731 491 924 answers to any question