better error message for mergeHelpers and setState
Cheng Lou committed
Jan 5, 2014 at 21:54 UTC
3c40fb2e010a6b7ec8eaa510ad87d4838eea7609
2 files changed
+13
-6
src/core/ReactCompositeComponent.js
+8
@@ -772,6 +772,14 @@ var ReactCompositeComponentMixin = {
772
typeof partialState === 'object' || partialState == null,
773
'setState(...): takes an object of state variables to update.'
774
);
775
+ if (__DEV__){
776
+ if (partialState == null) {
777
+ console.warn(
778
+ 'setState(...): You passed an undefined or null state object; ' +
779
+ 'instead, use forceUpdate().'
780
+ );
781
+ }
782
+ }
783
// Merge with `_pendingState` if it exists, otherwise with existing state.
784
this.replaceState(
785
merge(this._pendingState || this.state, partialState),
src/vendor/core/mergeHelpers.js
+5
-6
@@ -66,9 +66,9 @@ var mergeHelpers = {
66
checkMergeArrayArgs: function(one, two) {
67
invariant(
68
Array.isArray(one) && Array.isArray(two),
69
- 'Critical assumptions about the merge functions have been violated. ' +
70
- 'This is the fault of the merge functions themselves, not necessarily ' +
71
- 'the callers.'
69
+ 'Tried to merge arrays, instead got %s and %s.',
70
+ one,
71
+ two
72
);
73
},
74
@@ -87,9 +87,8 @@ var mergeHelpers = {
87
checkMergeObjectArg: function(arg) {
88
invariant(
89
!isTerminal(arg) && !Array.isArray(arg),
90
- 'Critical assumptions about the merge functions have been violated. ' +
91
- 'This is the fault of the merge functions themselves, not necessarily ' +
92
- 'the callers.'
90
+ 'Tried to merge an object, instead got %s.',
91
+ arg
92
);
93
},
94