Giter VIP home page Giter VIP logo

Comments (1)

yinyinnnn avatar yinyinnnn commented on August 27, 2024 1

ES6对象的解构赋值的重命名:别名

在解构赋值过程中,如果想要对象中的属性名和变量名不一致,就可以给变量取别名

在对象的解构赋值过程中,还是会先找到同名的属性,然后在赋值给对应的变量别名

let { foo:haha } = { foo:'aaa'}
console.log(haha)
console.log(foo)

上述的代码中,foo是匹配模式,haha才是变量。真正被赋值的是变量haha,而不是foo

react的生命周期

QQ图片20210603104309

挂载时:constructor ->render ->componentDidMount
更新阶段:render -> componentDidUpdate
卸载时:componentWillUnmount

constructor

构造函数用于:

  1. 初始化state

  2. 为事件执行函数绑定实例

    注:如果不需要初始化数据或者绑定实例则不用创建构造函数

render

react中最重要且必须实现的方法,常用来:

  1. 创建虚拟dom
  2. 进行diff算法
  3. 更新dom
注:不能更改state

componentDidMount

  1. componentDidMount会在挂载后立即调用,常用来加载请求数据进行初始化
  2. 可以直接调用setState(),但是会因为额外渲染导致性能问题

componentDidUpdate

  1. componentDidUpdate在更新后会被立即调用,第一次渲染时不会被调用
  2. 可以直接调用setState(),但是必须包裹在条件语句中,否则会导致死循环

componentWillUnmount

  1. 在组件卸载和销毁之前调用,完成所有的清理和销毁工作
  2. 不能调用setState()

from blogs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.