Search code examples
javascriptreactjsfrontendreact-konvakonva

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?


Solution

  • 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