-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Add ReactIs.isValidElementType() #12483
Add ReactIs.isValidElementType() #12483
Conversation
Per the conversation on facebook#12453, there are a number of third-party libraries (particularly those that generate higher-order components) that are performing suboptimal validation of element types. This commit exposes a function that can perform the desired check without depending upon React internals.
You could put it in |
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.
Looks good to me.
Needs an update to the README but I can add that separately.
Thanks for the quick review. |
* Add React.isValidElementType() Per the conversation on facebook#12453, there are a number of third-party libraries (particularly those that generate higher-order components) that are performing suboptimal validation of element types. This commit exposes a function that can perform the desired check without depending upon React internals. * Move isValidElementType to shared/
Per the conversation on #12453, there are a number of third-party libraries (particularly those that generate higher-order components) that are performing suboptimal validation of element types.
This commit exposes a function that can perform the desired check without depending upon React internals.
In #12453, we discussed exposing this check within the new
react-is
package, but as I dug in, I lost confidence that that was indeed the right course of action.Today, element type validation occurs within
ReactElementValidator
.ReactElementValidator
has a dependency uponReactElement
, but lacks a dependency uponreact-is
. (In fact, the nothing within the corereact
package takes a dependency uponreact-is
.)It felt wrong to duplicate the existing type validation code in a separate package, and it also felt wrong to factor it into
react-is
and introduce a new dependency fromreact
toreact-is
. As such, I placed the type validation logic alongsideReact.isValidElement
withinReactElement
.I realize that expanding the surface area of React's top-level API is a dicey prospect, but I wanted to explain my reasoning and propose it in code. If you think an alternative implementation would be more ideal, please just let me know and I'll revise.