Skip to content
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

Provide a better error on React.cloneElement(null/undefined) #12491

Closed
grantCHG opened this issue Mar 30, 2018 · 4 comments
Closed

Provide a better error on React.cloneElement(null/undefined) #12491

grantCHG opened this issue Mar 30, 2018 · 4 comments

Comments

@grantCHG
Copy link

Do you want to request a feature or report a bug?

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

What is the expected behavior?

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
image

@grantCHG grantCHG changed the title When the incoming parameter for this.props.children is empty, React.cloneElement report errors When the incoming parameter"this.props.children" is undefined, React.cloneElement report errors Mar 30, 2018
@milesj
Copy link
Contributor

milesj commented Mar 30, 2018

Can you please provide more information and answer the questions?

@gaearon
Copy link
Collaborator

gaearon commented Apr 1, 2018

You can't call cloneElement on undefined. This is intentional. You can check isValidElement() before cloning if you'd like to be safe.

That said we should probably throw a better error.

@gaearon gaearon changed the title When the incoming parameter"this.props.children" is undefined, React.cloneElement report errors Provide a better error on React.cloneElement(null/undefined) Apr 1, 2018
@wherestheguac
Copy link
Contributor

Is this PR all that’s really needed for this? #12534

@gaearon
Copy link
Collaborator

gaearon commented Apr 10, 2018

Fixed by @nicolevy in #12534

@gaearon gaearon closed this as completed Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants