脚本宝典收集整理的这篇文章主要介绍了react源码阅读,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
setState
react/packages/react/src/ReactBaseClasses.js
/**
* Sets a subset of the state. Always use this to mutate
* state. You should treat `this.state` as immutable.
*
* There is no guarantee that `this.state` will be immediately updated, so
* accessing `this.state` after calling this method may return the old value.
*
* There is no guarantee that calls to `setState` will run synchronously,
* as they may eventually be batched together. You can PRovide an optional
* callback that will be executed when the call to setState is actually
* completed.
*
* When a function is provided to setState, IT will be called at some point in
* the Future (not synchronously). It will be called with the up to date
* component arguments (state, props, context). These values can be different
* From this.* because your function may be called after receiveProps but before
* shouldComponentUpdate, and this new state, props, and context will not yet be
* assigned to this.
*
* @param {object|function} partialState Next partial state or function to
* produce next partial state to be merged with current state.
* @param {?function} callback Called after state is updated.
* @final
* @protected
*/
Component.prototyPE.setState = function(partialState, callback) {
inVARiant(
typeof partialState === 'object' ||
typeof partialState === 'function' ||
partialState == null,
'setState(...): takes an object of state variables to update or a ' +
'function which returns an object of state variables.',
);
this.updater.enqueueSetState(this, partialState, callback, 'setState');
};
SyntheticEvent
参考
以上是脚本宝典为你收集整理的react源码阅读全部内容,希望文章能够帮你解决react源码阅读所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。