React PropTypes DOM element? React PropTypes DOM element? reactjs reactjs

React PropTypes DOM element?


PropTypes.instanceOf(Element)

Is working for me. You can also add isRequired:

PropTypes.instanceOf(Element).isRequired


You can check if the passed property is instance of Element:

The Element interface represents an object of a Document. This interface describes methods and properties common to all kinds of elements. Specific behaviors are described in interfaces which inherit from Element but add additional functionality. For example, the HTMLElement interface is the base interface for HTML elements, while the SVGElement interface is the basis for all SVG elements.

class Some extends React.Component {  render() {    return (      <div> Hello </div>    );  }}const validateDOMElem = (props, propName, componentName) => {  if (props[propName] instanceof Element === false) {    return new Error(      'Invalid prop `' + propName + '` supplied to' +      ' `' + componentName + '`. Validation failed.'    );  }}Some.propTypes = {  htmlElem: validateDOMElem,};const para = document.getElementById('para');ReactDOM.render(<Some htmlElem={para} />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script><div id="app"></div><p id="para"></p>