Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change cursor on Hover in react-konva

I'm using react-konva to create a UI for an application. I want it so that the cursor changes to a pointer when hovering over a Rect. There is documentation for how to do it with konva but not for react-konva. Can anyone help?

like image 937
SSPdude Avatar asked Mar 23 '26 18:03

SSPdude


1 Answers

It works very similarly to Konva demos.

<Rect
  width={50}
  height={50}
  fill="red"
  onMouseEnter={e => {
    // style stage container:
    const container = e.target.getStage().container();
    container.style.cursor = "pointer";
  }}
  onMouseLeave={e => {
    const container = e.target.getStage().container();
    container.style.cursor = "default";
  }}
/>

Demo: https://codesandbox.io/s/react-konva-cursor-style-demo-96in7

like image 160
lavrton Avatar answered Mar 25 '26 07:03

lavrton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!