I am trying to define my list of PropTypes for a class component. The component can accept either a regular DOM element or window
as its prop value. Currently, I have:
class FooContainer extends Component {
static propTypes = {
container: PropTypes.oneOfType([
PropTypes.element,
PropTypes.instanceOf(Element),
]),
};
static defaultProps = {
container: window,
};
constructor(props: any) {
super(props);
}
render() {
return (
<div />
);
}
}
However, when the component defaults to using window
as the container prop, the following error is thrown:
Warning: Failed prop type: Invalid prop `container` supplied to `FooContainer`.
As such, what is the valid PropType to use for property with value of window
?
PropTypes.instanceof(Window)
? – Andrew LiWindow
is undefined, if i trywindow
instead, i getFailed prop type: Right-hand side of 'instanceof' is not callable
. i guesswindow
is not instanceable? or doesnt have theinstanceof
method. – haxxxtoninstanceOf(window.constructor)
– Andrew Li