@samitouri / QOS-React-2 / commits / 6d7c847f30

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

Rauno Freiberg committed Feb 22, 2018 at 22:06 UTC 6d7c847f30bcf60fa64daca68edceac56dd25da7
1 file changed +10
packages/react-reconciler/src/ReactFiberBeginWork.js
+10
@@ -869,6 +869,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
869 workInProgress.stateNode = observedBits;
870
871 const render = newProps.children;
872 +
873 + if (typeof render !== 'function') {
874 + invariant(
875 + false,
876 + "A context consumer was rendered with multiple children, or a child that isn't a function. " +
877 + 'A context consumer expects a single child that is a function. ' +
878 + 'If you did pass a function, make sure there is no trailing or leading whitespace around it.',
879 + );
880 + }
881 +
882 const newChildren = render(newValue);
883 reconcileChildren(current, workInProgress, newChildren);
884 return workInProgress.child;