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

前端 未结 13 2282
旧时难觅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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 04:35

    I know It's been a while since this question was asked but I just run into the same issue of inconsistency with onMouseLeave() What I did is to use onMouseOut() for the drop-list and on mouse leave for the whole menu, it is reliable and works every time I've tested it. I saw the events here in the docs: https://facebook.github.io/react/docs/events.html#mouse-events here is an example using https://www.w3schools.com/bootstrap/bootstrap_dropdowns.asp:

    handleHoverOff(event){
      //do what ever, for example I use it to collapse the dropdown
      let collapsing = true;
      this.setState({dropDownCollapsed : collapsing });
    }
    
    render{
      return(
        
      )
    }
    

提交回复
热议问题