From 48d15f0a27b77f3a532fa853fd027481ae33cc9a Mon Sep 17 00:00:00 2001 From: Rauno Date: Thu, 22 Feb 2018 21:29:22 +0200 Subject: [PATCH] Add a clearer error message for the Consumer render (#12241) --- packages/react-reconciler/src/ReactFiberBeginWork.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 7e2be7b79c5..b13a7d757a1 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -869,6 +869,16 @@ export default function( workInProgress.stateNode = observedBits; const render = newProps.children; + + if (typeof render !== 'function') { + invariant( + false, + "A context consumer was rendered with multiple children, or a child that isn't a function. " + + 'A context consumer expects a single child that is a function. ' + + 'If you did pass a function, make sure there is no trailing or leading whitespace around it.', + ); + } + const newChildren = render(newValue); reconcileChildren(current, workInProgress, newChildren); return workInProgress.child;