CNode

关于react的setState的updater

问答
Mmsforest发布于8 年前最后回复8 年前1 回复2705 浏览0 收藏
function ReactComponent(props, context, updater) {
  this.props = props;
  this.context = context;
  this.refs = emptyObject;
  this.updater = updater || ReactNoopUpdateQueue;
}
ReactComponent.prototype.setState = ...

// 我找到new组件的时候会注入一个updater
var ReactCompositeComponent = {
  mountComponent(){
    var inst = new Component(publicProps, publicContext, updateQueue);
  }
}

// 如果是按照以上方式传递
class Test extends Component{
  constructor(props){
    super(props); // 这里我一般不写完整
  }
}
/**
 * 所以问题就在这里,这里不传入第三个参数,为啥setState里面的this.updater还能正常用,求解答
 * 是注入的地方没找到??
 */
查看回复

回复 (1)

D
dislido#1·8 年前

因为this.updater = updater || ReactNoopUpdateQueue;

参与回复
登录后即可参与回复。登录