美文网首页
React生命周期

React生命周期

作者: AnnaJIAN | 来源:发表于2020-04-01 23:27 被阅读0次

Initialization 初始化
Mounting:挂载
Updation:更新
Unmounting:销毁

constructor构造函数,它是ES6的基本语法。虽然它和生命周期函数的性质一样,但不能认为是生命周期函数。

  1. Mounting
    componentWillMount : 在组件即将被挂载到页面的时刻执行。
    render : 页面state或props发生变化时执行。
    componentDidMount : 组件挂载完成时被执行。

componentWillMount和componentDidMount这两个生命周期函数,只在页面刷新时执行一次,而render函数是只要有state和props变化就会执行。

  1. Updation
    1-shouldComponentUpdate---组件发生改变前执行
    2-componentWillUpdate---组件更新前,shouldComponentUpdate函数之后执行
    3-render----开始挂载渲染
    4-componentDidUpdate----组件更新之后执行
    shouldComponentUpdate return true componentWillUpdate 才会执行

componentWillReceiveProps
子组件接收到父组件传递过来的参数,父组件render函数重新被执行,这个生命周期就会被执行。
也就是说这个组件第一次存在于Dom中,函数是不会被执行的;
如果已经存在于Dom中,函数才会被执行。

  1. unMounting
    componentWillUnmount
    这个函数时组件从页面中删除的时候执行

利用生命周期函数优化性能。

相关文章

  • React概念图

    React概念图 React组件生命周期概念图 参考文档:React入门教程 组件生命周期React:组件生命周期...

  • React基础篇之组件的生命周期

    引出生命周期 react生命周期(旧) react生命周期(新) getSnapshotBeforeUpdate的...

  • React生命周期

    React v16.0前的生命周期 React v16.4+ 的生命周期图 React v16.9后这些生命周期钩...

  • React v16 生命周期

    React 16 生命周期 React 16.3 新增的生命周期方法 逐渐废弃的生命周期方法: 一般将生命周期分成...

  • 学习并实现react (4)

    实现生命周期 生命周期介绍 React 生命周期图 React 子组件在父组件下的生命周期流程 实现 compon...

  • React面试题 整理脑图

    react基础 React生命周期 react-router react进阶 react Hooks redux 其他

  • react/vue常见问题整理

    一、react 1. react生命周期 react 16生命周期相对于15的变化:componentWillMo...

  • React 组件生命周期

    组件生命周期 参考阅读: component-lifecycle react组件生命周期过程说明 react 组件...

  • 《深入React技术栈》学习笔记Ⅲ

    以下的生命周期都是在 React 15 的生命周期, React 16 的生命周期 API 已经发生变化。Reac...

  • React总结

    [toc] 1.React组件生命周期 1.1 生命周期图 组件的生命周期的图如下: 具体可参考React 组件生...

网友评论

      本文标题:React生命周期

      本文链接:https://www.haomeiwen.com/subject/pexzuhtx.html