条件渲染
Conditional Rendering
## 元素变量
* 可以使用变量来储存元素,它可以帮助你有条件地渲染组件的一部分,而其他的渲染部分并不会因此而改变
* 使用 state 和 setState() 来控制
## 与运算符 &&
* 通过花括号包裹代码,你可以在 JSX 中嵌入任何表达式
```jsx harmony
function Mailbox(props) {
const unreadMessages = props.unreadMessages;
return (
<div>
<h1>Hello!</h1>
{unreadMessages.length > 0 &&
<h2>
You have {unreadMessages.length} unread messages.
</h2>
}
</div>
);
}三联运算符 condition ? true : false
阻止组件渲染
最后更新于