Add ReactIs.isValidElementType()#12483
Merged
bvaughn merged 3 commits intofacebook:masterfrom Mar 29, 2018
Merged
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.
Collaborator
You could put it in |
bvaughn
approved these changes
Mar 29, 2018
Contributor
bvaughn
left a comment
There was a problem hiding this comment.
Looks good to me.
Needs an update to the README but I can add that separately.
Contributor
Author
|
Thanks for the quick review. |
This was referenced Mar 30, 2018
This was referenced Apr 2, 2018
This was referenced Apr 17, 2018
rhagigi
pushed a commit
to rhagigi/react
that referenced
this pull request
Apr 19, 2018
* 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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-ispackage, but as I dug in, I lost confidence that that was indeed the right course of action.Today, element type validation occurs within
ReactElementValidator.ReactElementValidatorhas a dependency uponReactElement, but lacks a dependency uponreact-is. (In fact, the nothing within the corereactpackage 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-isand introduce a new dependency fromreacttoreact-is. As such, I placed the type validation logic alongsideReact.isValidElementwithinReactElement.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.