1.与运算符 &&
{unreadMessages.length > 0 &&
<h2>
You have {unreadMessages.length} unread messages.
</h2>
}
2.三目运算符
<div>
{isLoggedIn ? (
<LogoutButton onClick={this.handleLogoutClick} />
) : (
<LoginButton onClick={this.handleLoginClick} />
)}
</div>
3.箭头函数修改状态
handleToggleClick() {
this.setState(prevState => ({
showWarning: !prevState.showWarning
}));
}
网友评论