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.
Andrew Clark committed
Feb 21, 2017 at 14:40 UTC
adc1641fecbf95a2989265b345a43ab374ffcec1
1 file changed
+6
src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+6
@@ -850,6 +850,7 @@ var ReactCompositeComponent = {
850
// _pendingStateQueue which will ensure that any state updates gets
851
// immediately reconciled instead of waiting for the next batch.
852
if (willReceive && inst.componentWillReceiveProps) {
853
+ const beforeState = inst.state;
854
if (__DEV__) {
855
measureLifeCyclePerf(
856
() => inst.componentWillReceiveProps(nextProps, nextContext),
@@ -859,6 +860,11 @@ var ReactCompositeComponent = {
860
} else {
861
inst.componentWillReceiveProps(nextProps, nextContext);
862
}
863
+ const afterState = inst.state;
864
+ if (beforeState !== afterState) {
865
+ inst.state = beforeState;
866
+ inst.updater.enqueueReplaceState(inst, afterState);
867
+ }
868
}
869
870
// If updating happens to enqueue any new updates, we shouldn't execute new