Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If proptype of element what is the default?

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

like image 990
Got The Fever Media Avatar asked Dec 18 '22 05:12

Got The Fever Media


1 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,
}
like image 107
Félix Adriyel Gagnon-Grenier Avatar answered Dec 31 '22 02:12

Félix Adriyel Gagnon-Grenier