3 ms·
If you are writing JS styles, you don't have access to pseudoselectors like :hover. A quick solution adopted by many is simulating hover with onMouseEnter and o
by schwartzworld 6y ago
If you are writing JS styles, you don't have access to pseudoselectors like :hover. A quick solution adopted by many is simulating hover with onMouseEnter and onMouseLeave event handlers.
This can be remedied by using CSS or styled-components.
- madeofpalk 6y agoThis is nowhere near a common practice (I've never seen it on any work project, or on community projects). React does not promote or advocate or make it easier to do it this way, rather than the proper way in CSS.
- schwartzworld 6y agoIt is actually in the react documentation. https://reactjs.org/docs/dom-elements.html#style https://reactjs.org/docs/dom-elements.html#style I'm not saying that's how it should be done. I'm just clarifying what the author of the article was referring to.
- madeofpalk 6y agoCorrect, it is documented. That's what documentation is - to list out and describe the API surface. The entire documentation block for that is prefixed with a big yellow-box warning: > using the style attribute as the primary means of styling elements is generally not recommended. And then it links to https://reactjs.org/docs/faq-styling.html https://reactjs.org/docs/faq-styling.html which just says over and over again "use class names"
- schwartzworld 6y agoSo just to be clear A) it didn't always have that warning and B) I wasn't defending the practice. Did you read the article?