美文网首页
React性能缺陷,以及如何避免

React性能缺陷,以及如何避免

作者: Wang_Yong | 来源:发表于2018-11-01 17:32 被阅读0次

问题:动画组件,性能落后
相同组件过多,页面显示令人尴尬的动画效果
常见的陷阱

  • 不好的shouldComponentUpdate实现,为什么PureComponent也不能解决问题
  • 太过频繁的更改dom
  • 没有限制使用事件和回调
class ShouldNotUpdate extends React.Component {
  constructor(props){
    super(props)
  }
  shouldComponentUpdate(nextProps, nextState){
    return this.props.children !== nextProps.children
  }
  render(){
    return `I should be rendered only 1 time. actual times renderd : {++this.counter}`
  }
}

相关文章

网友评论

      本文标题:React性能缺陷,以及如何避免

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