Skip to content

Commit f635a5c

Browse files
raunofreibergrhagigi
authored andcommitted
Add a clearer error message for the Consumer render (facebook#12241) (facebook#12267)
1 parent 0f9a957 commit f635a5c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

+10
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,16 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
869869
workInProgress.stateNode = observedBits;
870870

871871
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+
872882
const newChildren = render(newValue);
873883
reconcileChildren(current, workInProgress, newChildren);
874884
return workInProgress.child;

0 commit comments

Comments
 (0)