S
S
sergemin2017-08-25 13:57:38
React
sergemin, 2017-08-25 13:57:38

Why pass props to constructor parameters in React?

I went through the official tutorial on the react and there was no such thing, but in some resources I noticed the following:

export default class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            title: 'Hello'
        }
render() {
return (
<div>{this.state.title}</div>
)
}

Why is props passed in constructor parameters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2017-08-25
@sergemin

Super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside your constructor.
https://stackoverflow.com/questions/30571875/whats...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question