I am new to JavaScript. I recently started to learn ReactJS and read about the component life cycle. I realized that when the component was initialized, the loop looks like this:
GetDefaultProps -> GetInitialState -> ComponentWillMount -> Render -> ComponentDidMount
I also read what getDefaultProps()gets called before any instances are created. If I have the following code:
class Sample extends React.Component {
constructor(props) {
super(props);
alert("In constructor");
}
getDefaultProps() {
alert("In getDefaultProps");
}
render() {
return <div></div>;
}
}
React.render(<Sample/>, document.getElementById('app'));
I assumed that I would warn "In getDefaultProps", then "In constructor". But only "In the constructor" is warned. Why is this so?
Amous source
share