
1、constructor 构造函数
注意事项:
(1) 方法内的第一句应为 super(props) ,这样可以避免构造方法后面的代码使用this.props时出现undefined错语
(2)在构造方法内对state应直接进行赋值,而不应调用setState()方法
(3) 避免拷贝props到state中,而要用this.props.xxx , 否则当props发生变化时,state将不能得到及时更新
// 构造函数
constructor(props) {
super(props)
}
state = {
}
网友评论