Got The Fever Media
Got The Fever Media

Reputation: 760

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

Upvotes: 5

Views: 4499

Answers (3)

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

Gregsarault
Gregsarault

Reputation: 1

I think undefinedshould work.

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

Upvotes: 0

vijayst
vijayst

Reputation: 21846

The default value could be:

React.createElement('div')

Upvotes: 5

Related Questions