-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Children of Consumer without new line gives "TypeError: render is not a function" #12241
Comments
We should show a nicer error message. I don't agree this should just render (it's too ambiguous, technically you have a text node there). But the message should make more sense. |
@gaearon I'd like to jump in on this! |
@elbaumpj it's all yours! |
Would someone mind pointing me in the right direction as to where I might find the relevant logic for this issue? I figured it would be in ReactContext.js, but I'm having trouble figuring out where the actual error message is being generated. Also, I wonder what the new message should say. Something like "The Consumer component's children must return a React element (JSX)"? To be honest, I'm not exactly sure why Consumer demands a new line for it's children. |
@elbaumpj you can find the call site using the stack trace from the error thrown in the codesandbox example posted by @ryepesg. The context consumer's render callback is called here: react/packages/react-reconciler/src/ReactFiberBeginWork.js Lines 871 to 872 in d529d20
We should add an
It doesn't actually require a newline, it just requires that you only render a single child that is a function. In this case, the space before the function created a text node. So when you do: <Consumer>{() => "foo"}</Consumer>
<Consumer> {() => "foo"}</Consumer>
@gaearon probably has better copy for this, but the gist of it should be something like:
|
@aweary that's all super helpful--thank you! |
Took a crack at this at #12267 - hope it's not an issue. |
I don't really appreciate that, I had clearly claimed this issue and just hadn't got a chance to make my PR yet. As it states in the docs:
|
Oops, sorry I merged without looking who took the issue :-( I guess it's fixed now, but @raunofreiberg please don't take claimed issues in the future. |
Got it. My apologies @elbaumpj. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I get a confusing error when not using a new line in the children of a Consumer un the new Context API:
https://codesandbox.io/s/13n733xp5j
Error:
Fix:
What is the expected behavior?
Component just getting redered
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.3.0-alpha.1 and 16.3.0-alpha.0, Chromium 63, Archilinux. React 16.2 didn't support the new Context Api.
The text was updated successfully, but these errors were encountered: