I quite like the inline CSS pattern in React and decided to use it.
However, you can't use the :hover
and similar selectors. So what's the best way to implement highlight-on-hover while using inline CSS styles?
One suggestion from #reactjs is to have a Clickable
component and use it like this:
<Clickable>
<Link />
</Clickable>
The Clickable
has a hovered
state and passes it as props to the Link. However, the Clickable
(the way I implemented it) wraps the Link
in a div
so that it can set onMouseEnter
and onMouseLeave
to it. This makes things a bit complicated though (e.g. span
wrapped in a div
behaves differently than span
).
Is there a simpler way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…