1. 作用域的修改放在constructor中

  constructor (props) {
    super(props)
    // 当组件的state或者props发生改变的的时候,render函数就是重新执行
    this.state = {
      inputValue: '',
      list: []
    }
    // 将this指向放在constructor中执行,在复杂的组件开发中节约性能
    this.handleInputChange = this.handleInputChange.bind(this)
    this.handleBtnChange = this.handleBtnChange.bind(this)
    this.handleItemDelete = this.handleItemDelete.bind(this)
  }

2. setState异步函数

setState内置了性能优化的机制,它是一个异步函数,可以把多次的数据改变结合成一次来做,这样的话降低虚拟DOM的对比频率,来提高性能

3.虚拟DOM

React底层运用了虚拟DOM,他还有同层比对,key值的调用,来提升虚拟DOM的比对速度,从而提升React的性能

4.借助shouldComponentUpdate生命周期函数

避免无谓的组件的render函数的运行

相关文章:

  • 2021-07-18
  • 2022-02-07
  • 2021-09-15
  • 2021-08-27
  • 2021-08-13
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-10-08
  • 2021-12-02
  • 2021-06-20
  • 2021-08-18
相关资源
相似解决方案