Skip to content

Commit

Permalink
Add a clearer error message for the Consumer render (facebook#12241) (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
raunofreiberg authored and LeonYuAng3NT committed Mar 22, 2018
1 parent 866e0e2 commit e3ccfb2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e3ccfb2

Please sign in to comment.