主题
条件
if
包裹 jsx
jsx
render(){
if (this.state.data === 'a') {
return <div>a</div>
} else {
return <div>other</div>
}
}
三元表达式
被 jsx 包裹,判断为真假返回不同的值
jsx
render(){
return {
<div>
{ this.state.data === 'a' ? 'a' : 'other' }
</div>
}
}
&&
被 jsx 包裹,只有为真的时候才返回值,不然不返回
jsx
render(){
return {
<div>
{ this.state.data === 'a' && 'a' }
</div>
}
}