immutable结合react 使用shouldComponentUpdate 渲染

先贴代码

import { is } from 'immutable';

shouldComponentUpdate: (nextProps = {}, nextState = {}) => {
  const thisProps = this.props || {}, thisState = this.state || {};

  if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
    return true;
  }

  for (const key in nextProps) {
    if (thisProps[key] !== nextProps[key] || !is(thisProps[key], nextProps[key])) {
      return true;
    }
  }

  for (const key in nextState) {
    if (thisState[key] !== nextState[key] || !is(thisState[key], nextState[key])) {
      return true;
    }
  }
  return false;
}


  我的问题是在 shouldComponentUpdate 方法中的这两个参数,也就是nextProps nextState 在组件的运行过程中,我想知道这两个参数的值是怎么来的呢? 初始值是空的,那么每次运行should 不还是空的吗? 
    弟弟不懂,请哥哥们耐心回答一下!!

  另外弟弟最近在学习immutable.js 配置 reacat  请问大家你们有没有好的学习链接或者是示例代码吗? 请哥哥们分享一下.....
阅读 2.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进