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
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
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 ;)