How can I access a hover state in reactjs?

前端 未结 4 668
清酒与你
清酒与你 2021-01-30 04:40

I have a sidenav with a bunch of basketball teams. So I would like to display something different for each team when one of them is being hovered over. Also, I am using Reactjs

4条回答
  •  一向
    一向 (楼主)
    2021-01-30 05:31

    React components expose all the standard Javascript mouse events in their top-level interface. Of course, you can still use :hover in your CSS, and that may be adequate for some of your needs, but for the more advanced behaviors triggered by a hover you'll need to use the Javascript. So to manage hover interactions, you'll want to use onMouseEnter and onMouseLeave. You then attach them to handlers in your component like so:

     this.someHandler}
        onMouseLeave={() => this.someOtherHandler}
    />
    

    You'll then use some combination of state/props to pass changed state or properties down to your child React components.

提交回复
热议问题