-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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-is] Add elementType API #12932
Conversation
Details of bundled changes.Comparing: ff724d3...c40c389 react-is
Generated by 🚫 dangerJS |
cc @sebmarkbage I don't think we (particularly Sebastian) want to expand the scope of this library. Aside from the question of scope, I think the resulting API would be pretty confusing, e.g. |
Yeah, Im not sure about the API name. I chose |
This would be useful for enzyme as well: enzymejs/enzyme#1701 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introspection is bad. It breaks modularity since you can no longer safely wrap these. E.g. the compiler really wants this to be safe.
We are likely going to move more of these to actually return stateless functional component wrappers instead of symbols so that it is always safe to wrap them because the consumer can't introspect them.
case 'string': | ||
case 'function': | ||
return REACT_ELEMENT_TYPE; | ||
case 'object': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very likely that we're going to do a breaking change and actually turn these into just functions.
There are existing use cases for this that are being implemented with even less safe introspection, so if those use cases are valid (enzyme, host-non-react-statics) than some form of introspection seems inevitable. Otherwise, alternative solutions that are safe and sanctioned need to be discussed. |
Yeah I'm all about this being safer, but no introspection doesn't seem feasible for enzyme, dev-tools, etc. There is always s a tension between safety for "normal" users and hooks for those building tooling on top of and for React. Things like Enzyme not having to be baked into react is clearly a win for everyone, it'd be great if we could strike the right balance here. |
Resolves #12882
Adds an API for checking what the element type would be if the value was passed to
React.createElement
. It's essentiallyisValidElementType
except that it returns the element type.