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

前端 未结 13 2286
旧时难觅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:50

    You can't with inline styling alone. Do not recommend reimplementing CSS features in JavaScript we already have a language that is extremely powerful and incredibly fast built for this use case -- CSS. So use it! Made Style It to assist.

    npm install style-it --save

    Functional Syntax (JSFIDDLE)

    import React from 'react';
    import Style from 'style-it';
    
    class Intro extends React.Component {
      render() {
        return Style.it(`
          .intro:hover {
            color: red;
          }
    
        `,
          

    CSS-in-JS made simple -- just Style It.

    ); } } export default Intro;

    JSX Syntax (JSFIDDLE)

    import React from 'react';
    import Style from 'style-it';
    
    class Intro extends React.Component {
      render() {
        return (
          
      }
    }
    
    export default Intro;
    

提交回复
热议问题