better error message for mergeHelpers and setState

This commit is contained in:
Cheng Lou
2014-01-05 21:54:24 -08:00
parent 5b43a2e6d7
commit 3c40fb2e01
2 changed files with 13 additions and 6 deletions

View File

@@ -772,6 +772,14 @@ var ReactCompositeComponentMixin = {
typeof partialState === 'object' || partialState == null,
'setState(...): takes an object of state variables to update.'
);
if (__DEV__){
if (partialState == null) {
console.warn(
'setState(...): You passed an undefined or null state object; ' +
'instead, use forceUpdate().'
);
}
}
// Merge with `_pendingState` if it exists, otherwise with existing state.
this.replaceState(
merge(this._pendingState || this.state, partialState),

View File

@@ -66,9 +66,9 @@ var mergeHelpers = {
checkMergeArrayArgs: function(one, two) {
invariant(
Array.isArray(one) && Array.isArray(two),
'Critical assumptions about the merge functions have been violated. ' +
'This is the fault of the merge functions themselves, not necessarily ' +
'the callers.'
'Tried to merge arrays, instead got %s and %s.',
one,
two
);
},
@@ -87,9 +87,8 @@ var mergeHelpers = {
checkMergeObjectArg: function(arg) {
invariant(
!isTerminal(arg) && !Array.isArray(arg),
'Critical assumptions about the merge functions have been violated. ' +
'This is the fault of the merge functions themselves, not necessarily ' +
'the callers.'
'Tried to merge an object, instead got %s.',
arg
);
},