html:
<p class="class1 class2">xxx</p>
react:
render(){
return <p className={ this.state.isError && 'box-color' }>hello world</p>
}
三目运算符
render(){
return <p className={ this.state.isShow ? 'box-show' : 'box-hide' }>hello world</p>
}
使用函数:
render(){
return <p className={ this.getIsError() }>hello world</p>
}
多个class:
render(){
return <div className={classnames.join(" ")}>{value.value}</div>
}
react-native:
const styles = StyleSheet.create({
bigblue: {
color: 'blue',
fontWeight: 'bold',
fontSize: 30,
},
red: {
color: 'red',
},
});
<Text style={[styles.red, styles.bigblue]}>red, then bigblue</Text>