我们都知道Render在组件实例化和存在期时都会被执行。实例化在componentWillMount执行完成后就会被执行,这个没什么好说的。在这里我们主要分析存在期组件更新时的执行。
存在期的方法包含:
– componentWillReceiveProps
– shouldComponentUpdate
– componentWillUpdate
– render
– componentDidUpdate
这些方法会在组件的状态或者属性发生发生变化时被执行,如果我们使用了Redux,那么就只有当属性发生变化时被执行。下面我们将从几个场景来分析属性的变化。
首先我们创建了HelloWorldComponent,代码如下所示:
import * as React from "react";
class HelloWorldComponent extends React.Component {
constructor(props) {
super(props);
}
componentWillReceiveProps(nextProps) {
console.log(
版权声明:本文为zhaoruda原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。