zoukankan      html  css  js  c++  java
  • react 生命周期 个人见解

    初始化/实例期

    gitDefaultprops 获取组件的默认props状态

    gitInitialstate 类定义方式或是直接在构造函数中挂载state

    componentWillMount  组件挂载之前

    render 渲染

    componentDidMount 组件渲染完成之后

    更新/存在期

    componentWillReceivePrors(nextprops) props更改的时候会触发,参数为新的props

    shouldcomponentUpDate(nextprops,nextstate)props的更改或者state的更改都会触发此周期,参数为新的props和新的props和新的state,改周期函数是唯一一个可以阻止是否需要重新渲染的周期,必须有一个返回值且为布尔值

    componentWillUpdate(nextprops,nextstate) props的更改或者state的更改都会触发此函数周期,参数为新的props和新的state

    componentDidUpdata(prevprops,prevstate)Props的更改或者state的更改都会触发此函数,参数为旧的props 和旧的 state

    销毁期/卸载

    componentWillUnmount()组件卸载时候触发

    react新的生命周期

    getDerivedStateFromProps   该方法属于类的静态方法,他在组件实例化或者接受到新的props是被触发,可以return 一个对象来标识需要更改的state状态,如无需更改直接return null 完全替代componentWillReceiveProps 周期

    getSnapshotBeforeUpdate 该方法在实际改动(比如DOM更新)发生前的瞬间 被调用,返回值将作为‘componentDidUpdata’的第三个参数,在此时方法获取到DOM信息化componentWillUpdata更加可靠

  • 相关阅读:
    Java 基础
    Java 数据类型
    Spring 拦截器实现事物
    SSH 配置日记
    Hibernate 知识提高
    Jsp、Servlet
    leetcode 97. Interleaving String
    leetcode 750. Number Of Corner Rectangles
    leetcode 748. Shortest Completing Word
    leetcode 746. Min Cost Climbing Stairs
  • 原文地址:https://www.cnblogs.com/lxl123/p/10607680.html
Copyright © 2011-2022 走看看