那这个呢。让我们定义一个简单的帮助If组件。
var If = React.createClass({
    render: function() {
        if (this.props.test) {
            return this.props.children;
        }
        else {
            return false;
        }
    }
});
并以这种方式使用它:
render: function () {
    return (
        <div id="page">
            <If test={this.state.banner}>
                <div id="banner">{this.state.banner}</div>
            </If>
            <div id="other-content">
                blah blah blah...
            </div>
        </div>
    );
}
更新:随着我的回答越来越受欢迎,我觉得有必要警告您与此解决方案相关的最大危险。正如在另一个答案中指出的那样<If />,无论条件为真还是假,始终执行组件内的代码。因此,如果是(注意第二行的属性访问),以下示例将失败:bannernull
<If test={this.state.banner}>
    <div id="banner">{this.state.banner.url}</div>
</If>
使用时必须小心。我建议阅读替代(更安全)方法的其他答案。
更新 2:回过头来看,这种方法不仅危险,而且极其繁琐。这是一个典型的例子,当开发人员(我)试图将他知道的模式和方法从一个领域转移到另一个领域时,但它并没有真正起作用(在这种情况下是其他模板语言)。
如果您需要一个条件元素,请这样做:
render: function () {
    return (
        <div id="page">
            {this.state.banner &&
                <div id="banner">{this.state.banner}</div>}
            <div id="other-content">
                blah blah blah...
            </div>
        </div>
    );
}
如果您还需要 else 分支,只需使用三元运算符: 
{this.state.banner ?
   <div id="banner">{this.state.banner}</div> :
   <div>There is no banner!</div>
}
它更短、更优雅、更安全。我用它所有的时间。唯一的缺点是你不能那么else if容易地进行分支,但这通常并不常见。
无论如何,这要归功于JavaScript 中的逻辑运算符的工作方式。逻辑运算符甚至允许像这样的小技巧:
<h3>{this.state.banner.title || 'Default banner title'}</h3>