First set the Ng-class of a ANGULARJS code:
Easier to understand the Angularjs Ng-class set style code, then how do we use react to implement it?
First set a variable in state such as: Isshowloginmenu, change its value in different scenes, and then bind to the class style
<i classname={"Header-help-icon down" + (This.state.isShowLoginMenu? ' Up ': '}></i>
Or
<span id= "Vip-header-logo" classname={' Vip-logo icon-vip-v ' + this.state.viplevel}></span>
Using Angularjs We can do this:
<div class= "logined" ng-show= "IsLogin" > Login </div> <div class= "logined"
ng-if= "IsLogin" > Hello, { username}</div>
<div class= "No-login" ng-hide= "IsLogin" > Not signed in </div>
So how do we use react to achieve such a scenario?
React.createclass ({
getinitialstate:function () {return
{
islogin:true,
userName: ' Joe '
};
} ,
render:function () {
var islogin = this.state.isShowLoginMenu,
loginhtml;
if (islogin) {
loginhtml =
<div classname= "logined" >
login, Welcome to {this.state.userName}
</ div>;
} else {
loginhtml =
<div classname= "No-login" >
not logged in
</div>;
}
Return (
<div classname= "user" >
{loginhtml}
</div>
);
}