2

I am looking for a way to draw a shape based on a mouse event in react-konva, but have only been able to find methods to draw shapes on the screen statically

Namya LG
  • 31
  • 5

1 Answers1

1

Yes, you can add onClick event to your Stage like <Stage width={yourWidth} height={yourHeight} ref={stageRef} onClick={handleClick}> and then

const handleClick = (e) => {
    setCircles((prevCircles) => [
      ...prevCircles,
      {
        x: e.currentTarget.pointerPos.x,
        y: e.currentTarget.pointerPos.y,
        fill: "blue"
      }
    ]);
  }

and don't forget to .map your circles state inside of Stage ;)

BepaTest
  • 13
  • 2