Reputation: 760
if I try to set a proptype as PropTypes.element
, not required, what is the proper default?
static propTypes = {
expandable: PropTypes.bool,
popover: PropTypes.element,
}
static defaultProps = {
expandable: false,
popover: () => {},
}
Thanks
Upvotes: 5
Views: 4499
Reputation: 8885
The proper default, or non existing component, in React is null
. You can use it in render()
like that:
render() {
return (
<div>{this.props.popover ? this.props.popover : null}</div>
);
}
or simply define it in staticProps:
static defaultProps = {
expandable: false,
popover: null,
}
Upvotes: 8
Reputation: 1
I think undefined
should work.
static defaultProps = {
expandable: false,
popover: undefined,
}
Upvotes: 0