Add a clearer error message for the Consumer render (#12241) (#12267)

This commit is contained in:
Rauno Freiberg authored and Dan Abramov committed 2018-02-22 20:06:17 +00:00
1 parent cf58f296e9
commit 6d7c847f30
1 file changed
+10
+10
View File
@@ -869,6 +869,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
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;