According to the Usage section in the README, elementType is for a "React element type (ie. MyComponent)".
// A React element type (ie. MyComponent).
optionalElementType: PropTypes.elementType,
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/
function Test() {
return (
<Typography component="span">Text</Typography>
);
}
Typography.propTypes = {
component: PropTypes.elementType,
children: PropTypes.node,
};
function Typography(props) {
const Component = props.component || "p";
return <Component>{props.children}</Component>;
}
ReactDOM.render(
<Test />,
document.getElementById('container')
);