HTMLDocument的Proptype是什么

时间:2017-06-09 22:36:00

标签: javascript reactjs

我有一个接受window.document

的道具
<MyComponent container={document} />

如何定义这个proptype?

MyComponent.propTypes = {
  container: Proptypes.????.isRequired
};

1 个答案:

答案 0 :(得分:2)

啊!以下使用instanceOf ...

工作
container: PropTypes.instanceOf(HTMLDocument).isRequired

<强>更新

&#39; HTMLDocument的&#39;在IE10中不起作用。

如果您需要支持IE10,可以使用

PropTypes.instanceOf(Document)

如上所述here,抽象接口HTMLDocument扩展了Document接口。