What do you think are good ways to handle pseudo selector styles using the React inline style? What are the advantages and disadvantages?
Say you have a styles.js file for each React component. You create your component using this stylesheet. But then you want to make the hover effect on the button (or something else).
One way is to have a global CSS file and handle the style pseudo-selectors this way. Here the label sticker class comes from the global CSS file, and styles.label from the component style file.
<ControlLabel style={styles.label} className='label-hover'> Email </ControlLabel>
Another way is to style the components based on certain conditions (which may be caused by a state or some other). Here, if the hover state is true, use styles.button and styles.buttonHover, otherwise just use style.button.
<section style={(hovered !== true) ? {styles.button} : {...styles.button, ...styles.buttonHover }> </section>
Both approaches seem hacky. If anyone has a better approach, I would love to know. Thanks!
css reactjs
Vien Tang
source share