Correct way to handle conditional styling in React

前端 未结 9 1249
逝去的感伤
逝去的感伤 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:49

    I came across this question while trying to answer the same question. McCrohan's approach with the classes array & join is solid.

    Through my experience, I have been working with a lot of legacy ruby code that is being converted to React and as we build the component(s) up I find myself reaching out for both existing css classes and inline styles.

    example snippet inside a component:

    // if failed, progress bar is red, otherwise green 
    

    Again, I find myself reaching out to legacy css code, "packaging" it with the component and moving on.

    So, I really feel that it is a bit in the air as to what is "best" as that label will vary greatly depending on your project.

提交回复
热议问题