From 6d7c847f30bcf60fa64daca68edceac56dd25da7 Mon Sep 17 00:00:00 2001 From: Rauno Freiberg Date: Thu, 22 Feb 2018 22:06:17 +0200 Subject: [PATCH] Add a clearer error message for the Consumer render (#12241) (#12267) --- 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 7e2be7b79c..b13a7d757a 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;