How do you Hover in ReactJS? - onMouseLeave not registered during fast hover over

前端 未结 13 2256
旧时难觅i
旧时难觅i 2020-11-28 04:23

How can you achieve either a hover event or active event in ReactJS when you do inline styling?

I\'ve found that the onMouseEnter, onMouseLeave approach is buggy, so

13条回答
  •  遥遥无期
    2020-11-28 04:31

    Note: This answer was for a previous version of this question where the question asker was trying to use JavaScript to apply css styles… which can simply be done with CSS.

    A simple css-only solution.

    For applying basic styles, CSS is simpler and more performant that JS solutions 99% of the time. (Though more modern CSS-in-JS solutions — eg. React Components, etc — are arguably more maintainable.)

    Run this code snippet to see it in action…

    .hover-button .hover-button--on,
    .hover-button:hover .hover-button--off {
      display: none;
    }
    
    .hover-button:hover .hover-button--on {
      display: inline;
    }

提交回复
热议问题