Should be able to setState inside cWRP before assigning to this.state
...without dropping the update. This won't work the other way around, if you assign to this.state before calling setState. we'll add a deprecation warning so people stop relying on this pattern.
This commit is contained in:
parent
d98a3d9269
commit
adc1641fec
|
@ -850,6 +850,7 @@ var ReactCompositeComponent = {
|
|||
// _pendingStateQueue which will ensure that any state updates gets
|
||||
// immediately reconciled instead of waiting for the next batch.
|
||||
if (willReceive && inst.componentWillReceiveProps) {
|
||||
const beforeState = inst.state;
|
||||
if (__DEV__) {
|
||||
measureLifeCyclePerf(
|
||||
() => inst.componentWillReceiveProps(nextProps, nextContext),
|
||||
|
@ -859,6 +860,11 @@ var ReactCompositeComponent = {
|
|||
} else {
|
||||
inst.componentWillReceiveProps(nextProps, nextContext);
|
||||
}
|
||||
const afterState = inst.state;
|
||||
if (beforeState !== afterState) {
|
||||
inst.state = beforeState;
|
||||
inst.updater.enqueueReplaceState(inst, afterState);
|
||||
}
|
||||
}
|
||||
|
||||
// If updating happens to enqueue any new updates, we shouldn't execute new
|
||||
|
|
Loading…
Reference in New Issue