Closed gbroques closed 3 years ago
elementType
calls into react-is
's isValidElementType
function, which does not check the contents of the string: https://github.com/facebook/react/blob/master/packages/shared/isValidElementType.js
In other words, a valid element type is:
@ljharb Thank you for clarifying! Would a PR to update the Usage comment to the following be welcomed?
// A React element type (eg. MyComponent).
// a function, string, or "element-like" object (eg. React.Fragment, Suspense, etc.)
// see https://github.com/facebook/react/blob/master/packages/shared/isValidElementType.js
optionalElementType: PropTypes.elementType,
sure, couldn't hurt.
According to the Usage section in the README,
elementType
is for a "React element type (ie. MyComponent)".However, I can also pass a string corresponding to the name of a DOM element (e.g. "span", "div", etc.) without triggering a prop types warning.
Will
elementType
validate the string is a valid DOM element, or can I pass"bologna"
without triggering a prop types warning?It's not clear what
elementType
is validating, and what's allowable from the Usage section alone.Can we clarify this?
Consider the following example.
JS Fiddle: https://jsfiddle.net/h02ka7up/63/