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
Asked
Active
Viewed 218 times
1 Answers
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
-
Hey, I'm trying to use your methode to create a
could you maybe help me? – Yohav Rn Dec 29 '22 at 21:44