React pseudo selector inline styling

后端 未结 2 535
感动是毒
感动是毒 2020-12-13 18:53

What do you think are good ways to handle styling pseudo selectors with React inline styling? What are the gains and drawbacks?

Say you have a styles.js file for eac

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 19:20

    My advice to anyone wanting to do inline styling with React is to use Radium as well.

    It supports :hover, :focus and :active pseudo-selectors with minimal effort on your part

    import Radium from 'radium'
    
    const style = {
      color: '#000000',
      ':hover': {
        color: '#ffffff'
      }
    };
    
    const MyComponent = () => {
      return (
        
    ); }; const MyStyledComponent = Radium(MyComponent);

    Update 04/03/2018

    This has been getting a few upvotes lately so I feel like I should update it as I've stopped using Radium. I'm not saying Radium isn't still good and great for doing psuedo selectors, just that it's not the only option.

    There has been a large number of css-in-js libraries since Radium came out which are worth considering. My current pick of the bunch is emotion, but I encourage you to try a few out and find the one that fits you best.

    • emotion -

提交回复
热议问题