Correct way to handle conditional styling in React

前端 未结 9 1233
逝去的感伤
逝去的感伤 2020-11-27 04:25

I\'m doing some React right now and I was wondering if there is a \"correct\" way to do conditional styling. In the tutorial they use

style={{
  textDecorati         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 04:42

    The best way to handle styling is by using classes with set of css properties.

    example:

    
    
    getColor() {
        let class = "badge m2";
        class += this.state.count===0 ? "warning" : danger;
        return class;
    }
    

提交回复
热议问题