diff --git a/packages/react-reconciler/src/ReactChildFiber.new.js b/packages/react-reconciler/src/ReactChildFiber.new.js index 83362b5e15411..c5206e46c4899 100644 --- a/packages/react-reconciler/src/ReactChildFiber.new.js +++ b/packages/react-reconciler/src/ReactChildFiber.new.js @@ -222,14 +222,15 @@ function coerceRef( function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) { if (returnFiber.type !== 'textarea') { + const childString = Object.prototype.toString.call(newChild); invariant( false, 'Objects are not valid as a React child (found: %s). ' + 'If you meant to render a collection of children, use an array ' + 'instead.', - Object.prototype.toString.call(newChild) === '[object Object]' + childString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' - : newChild, + : childString, ); } } diff --git a/packages/react-reconciler/src/ReactChildFiber.old.js b/packages/react-reconciler/src/ReactChildFiber.old.js index 1f774b26813bb..036b84a5493a0 100644 --- a/packages/react-reconciler/src/ReactChildFiber.old.js +++ b/packages/react-reconciler/src/ReactChildFiber.old.js @@ -222,14 +222,15 @@ function coerceRef( function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) { if (returnFiber.type !== 'textarea') { + const childString = Object.prototype.toString.call(newChild); invariant( false, 'Objects are not valid as a React child (found: %s). ' + 'If you meant to render a collection of children, use an array ' + 'instead.', - Object.prototype.toString.call(newChild) === '[object Object]' + childString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' - : newChild, + : childString, ); } }