官术网_书友最值得收藏!

The constructor() method

The constructor method of React Component gets invoked first when the component is mounted. Here, we can set the state of the component.

Here's an example of constructor in React.Component:

constructor(props) {
super(props);
this.state = {
value: props.initialValue
};
}
Using  this.props  inside the constructor, we need to call super(props) to access and call functions of parents; otherwise, you will get  this.props  undefined in the constructor because React sets the  .props  on the instance from outside   immediately  after calling constructor, but it will not affect when you are using this.props inside the render method.
主站蜘蛛池模板: 江山市| 定襄县| 玉门市| 靖边县| 温泉县| 米林县| 行唐县| 嘉祥县| 花莲县| 敦煌市| 平罗县| 门头沟区| 富锦市| 莲花县| 栖霞市| 永丰县| 丹巴县| 简阳市| 玛多县| 页游| 江华| 黄浦区| 乾安县| 九江县| 北辰区| 永平县| 湛江市| 中方县| 宁阳县| 赞皇县| 安岳县| 临城县| 库车县| 内黄县| 满洲里市| 长阳| 无极县| 贵溪市| 江孜县| 化德县| 长葛市|