If proptype of element what is the default?

Viewed 3739

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

3 Answers

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,
}

I think undefinedshould work.

static defaultProps = {
  expandable: false,
  popover: undefined,
}
Related