1class App extends Component {
2 constructor() {
3 super()
4 this.state = { isRed: true }
5 }
6
7 render() {
8 const isRed = this.state.isRed
9
10 return <p className={isRed ? 'class1' : 'class2'}>Example Text</p>
11 }
12}
1// return class names from a function
2getClass(someInput){
3 switch(someInput){
4 case '1': {
5 return 'class1'
6 }
7 case '2': {
8 return 'class2'
9 }
10 case '3': {
11 return 'class3'
12 }
13 }
14}
15
16render() {
17 return (
18 <p className={this.getClass('1')}>
19 Example Text
20 </p>
21 );
22}