React - 从返回条件中删除空DIV

时间:2018-02-06 08:01:49

标签: javascript reactjs ecmascript-6

我试图从html中删除这个空的<div>

class ParentComp extends Component {
...

return (
      <div>
        {
          GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode ?
            this.props.children
            :
            ''
        }
      </div>
    );

用例:

<ParentComp countryCode={COUNTRY_CODE.be.value}>
   <ItemConfigure {...this.props} />
</ParentComp>

如果不匹配,则打印为空。

1 个答案:

答案 0 :(得分:2)

试试这个:

render() {
    return GlobalAppHandlerStore.getCurrentState().countryCode === this.props.countryCode && (<div>{this.props.children}</div>);
}