Avoid .valueOf to close #20594 (#20617)
Dima Tisnek committed
Jan 20, 2021 at 10:59 UTC
2e948e0d91360e4763594854be84347737e4b1f6
2 files changed
+6
-4
packages/react-reconciler/src/ReactChildFiber.new.js
+3
-2
@@ -222,14 +222,15 @@ function coerceRef(
222
223
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
224
if (returnFiber.type !== 'textarea') {
225
+ const childString = Object.prototype.toString.call(newChild);
226
invariant(
227
false,
228
'Objects are not valid as a React child (found: %s). ' +
229
'If you meant to render a collection of children, use an array ' +
230
'instead.',
230
- Object.prototype.toString.call(newChild) === '[object Object]'
231
+ childString === '[object Object]'
232
? 'object with keys {' + Object.keys(newChild).join(', ') + '}'
232
- : newChild,
233
+ : childString,
234
);
235
}
236
}
packages/react-reconciler/src/ReactChildFiber.old.js
+3
-2
@@ -222,14 +222,15 @@ function coerceRef(
222
223
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
224
if (returnFiber.type !== 'textarea') {
225
+ const childString = Object.prototype.toString.call(newChild);
226
invariant(
227
false,
228
'Objects are not valid as a React child (found: %s). ' +
229
'If you meant to render a collection of children, use an array ' +
230
'instead.',
230
- Object.prototype.toString.call(newChild) === '[object Object]'
231
+ childString === '[object Object]'
232
? 'object with keys {' + Object.keys(newChild).join(', ') + '}'
232
- : newChild,
233
+ : childString,
234
);
235
}
236
}