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

React.createElement mangles array passed as props #14743

Closed
IanKemp opened this issue Feb 1, 2019 · 2 comments
Closed

React.createElement mangles array passed as props #14743

IanKemp opened this issue Feb 1, 2019 · 2 comments

Comments

@IanKemp
Copy link

IanKemp commented Feb 1, 2019

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

Bug. I think. Maybe.

What is the current behavior?

https://jsfiddle.net/oyn139b4/2/

An array passed as props gets transformed into an object, meaning that attempting to call array methods on the props in the component fails. This behaviour, and why it happens/is necessary, is not documented anywhere.

There was a warning added to this effect in pull 6134 but it's gone AWOL somewhere along the line.

What is the expected behavior?

  1. Update React to not mangle arrays of props.

-or-

  1. Add an explanation as to why props cannot be a non-object to the React documentation.
  2. Restore the warning added in pull 6134 to prevent people from making this mistake in the future.

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

Latest, all browsers/OSes, don't know.

@marvinhagemeister
Copy link
Contributor

The props argument must be of type object to satisfy the requirements set by jsx. Allowing various other types there would make checking for special react properties like ref, key or children not only slower (remember createElement is in the hot path), but also more difficult.

@gaearon
Copy link
Collaborator

gaearon commented Feb 8, 2019

Yeah, it's not supported to have anything but plain objects as props.

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

No branches or pull requests

3 participants