我有一个接受window.document
<MyComponent container={document} />
如何定义这个proptype?
MyComponent.propTypes = {
container: Proptypes.????.isRequired
};
答案 0 :(得分:2)
啊!以下使用instanceOf
...
container: PropTypes.instanceOf(HTMLDocument).isRequired
<强>更新强>
&#39; HTMLDocument的&#39;在IE10中不起作用。
如果您需要支持IE10,可以使用
PropTypes.instanceOf(Document)
如上所述here,抽象接口HTMLDocument扩展了Document接口。