@samitouri / QOS-React / commits / ea622e52c2

Use warning instead of console.error

Andrew Clark committed Dec 15, 2016 at 17:34 UTC ea622e52c20b3e1b04862d41754dad5fb5c581c8
1 file changed +22 -15
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+22 -15
@@ -25,6 +25,8 @@ const {
25 TaskPriority,
26 } = require('ReactPriorityLevel');
27
28 +const warning = require('warning');
29 +
30 type PartialState<State, Props> =
31 $Subtype<State> |
32 (prevState: State, props: Props) => $Subtype<State>;
@@ -193,21 +195,26 @@ function insertUpdate(fiber : Fiber, update : Update, methodName : ?string) : vo
195 const queue2 = fiber.alternate ? ensureUpdateQueue(fiber.alternate) : null;
196
197 // Warn if an update is scheduled from inside an updater function.
196 - if (__DEV__ && typeof methodName === 'string' && (queue1.isProcessing || (queue2 && queue2.isProcessing))) {
197 - if (methodName === 'setState') {
198 - console.error(
199 - 'setState was called from inside the updater function of another' +
200 - 'setState. A function passed as the first argument of setState ' +
201 - 'should not contain any side-effects. Return a partial state object ' +
202 - 'instead of calling setState again. Example: ' +
203 - 'this.setState(function(state) { return { count: state.count + 1 }; })'
204 - );
205 - } else {
206 - console.error(
207 - `${methodName} was called from inside the updater function of ` +
208 - 'setState. A function passed as the first argument of setState ' +
209 - 'should not contain any side-effects.'
210 - );
198 + if (__DEV__ && typeof methodName === 'string') {
199 + if (queue1.isProcessing || (queue2 && queue2.isProcessing)) {
200 + if (methodName === 'setState') {
201 + warning(
202 + false,
203 + 'setState was called from inside the updater function of another' +
204 + 'setState. A function passed as the first argument of setState ' +
205 + 'should not contain any side-effects. Return a partial state ' +
206 + 'object instead of calling setState again. Example: ' +
207 + 'this.setState(function(state) { return { count: state.count + 1 }; })'
208 + );
209 + } else {
210 + warning(
211 + false,
212 + '%s was called from inside the updater function of setState. A ' +
213 + 'function passed as the first argument of setState ' +
214 + 'should not contain any side-effects.',
215 + methodName
216 + );
217 + }
218 }
219 }
220