关于 React 你应该了解的

生命周期

Screen Shot 2017-08-20 at 4.32.56 PM.png

终于找到这张图(出处《Mastering React Native》),特地测试了下,仅当state发生改变时,componentWillReceiveProps是不会被调用的,仅在props改变时调用。

  • componentWillMount、componentDidMount
    仅在初次渲染前后被调用一次,之后不会用到,无参数
  • componentWillReceiveProps(nextProps): 接受一个参数,每当props属性改变时被调用
  • componentShouldUpdate(nextProps, nextState): 默认返回 true, 即每当props或state改变时都渲染
  • componentWillUpdate(nextProps, nextState): render方法被调用前的最后一个方法
  • render: 渲染
  • componentDidUpdate(prevProps, prevState): 渲染后调用,参数为之前的props和state
  • componentWillUnmount(): 组件销毁前方法,一般用来清理定时器等
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容