更新组件的流程:
调用setState后,会调用shouldComponentUpdate 这个函数会判断要不要更新state如果要更新state 就会返回true 如果不要更新就会返回false 后面的componentWillUpdate 和 render 还有componentDidUpdate 也就都不会执行了,. shouldComponentUpdate这个函数默认返回true
componentWillUpdate 组件将要更新: 它的作用就是 获取更新前的数据 以及强制更新 不用通过shouldComponentUpdate 开关了
父组件一旦调用render 子组件 也会重新渲染 会经过 componentWIllReceiveProps shouldComponentUpdate componentWillUpdate render componentWillUmount等钩子函数
componentWIllReceiveProps 有个坑 第一次页面加载的时候 是不会调用这个钩子函数 重新渲染的时候才会调用这个钩子函数 。
componentDidUpdate:表示render执行后 调用的钩子函数。 就是页面加载完成后调用。开启定时器 发送网络请求 订阅消息。
componentWillUnmount :表示组件将要卸载的时候调用该钩子函数 比如 关闭定时器 取消订阅消息
总结: