0
0
Component.prototype.setState = function(update, callback) { // only clone state when copying to nextState the first time. let s; if (this._nextState != null && this._nextState !== this.state) { s = this._nextState; } else { s = this._nextState = assign({}, this.state); }
// Skip update if updater function returned null if (update == null) return;
if (this._vnode) { if (callback) { this._stateCallbacks.push(callback); } enqueueRender(this); } };
Component.prototype.setState = function(update, callback) { // only clone state when copying to nextState the first time. let s; if (this._nextState != null && this._nextState !== this.state) { s = this._nextState; } else { s = this._nextState = assign({}, this.state); }
// Skip update if
Library: react
/**
* Update component state and schedule a re-render.
* @this {import('./internal').Component}
* @param {object | ((s: object, p: object) => object)} update A hash of state
* properties to update with new values or a function that given the current
* state and props returns a new partial state
* @param {() => void} [callback] A function to be called once component state is
* updated
*/
Component.prototype.setState = function(update, callback) {
// only clone state when copying to nextState the first time.
let s;
if (this._nextState != null && this._nextState !== this.state) {
s = this._nextState;
} else {
s = this._nextState = assign({}, this.state);
}
if (typeof update == 'function') {
// Some libraries like `immer` mark the current state as readonly,
// preventing us from mutating it, so we need to clone it. See #2716
update = update(assign({}, s), this.props);
}
if (update) {
assign(s, update);
}
// Skip update if updater function returned null
if (update == null) return;
if (this._vnode) {
if (callback) {
this._stateCallbacks.push(callback);
}
enqueueRender(this);
}
};