Add shared utility isValidElementType to React #35228
Open
+18
−0
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.
What does this PR do?
This PR adds a new shared utility function
isValidElementTypeunderpackages/shared/.The function helps check whether a given value can be used as a valid React element type (string, function component, or component object).
Includes unit tests validating behavior for strings, functions, null/undefined, and objects.
Why is this useful?
In various parts of React codebase or third-party libraries, we often need to check if a variable is a valid element type before rendering or passing it further.
This helper standardizes that logic in one place, avoiding duplication and improving code readability and safety.
Checklist (as per React contributing guidelines)
yarn test)yarn prettier,yarn lint)yarn flow)Thank you for considering this contribution.