I am a complete beginner in react konva and trying to make a simple project. I just want to display a rectangle wherever user clicks so like if user clicked at 3 position he can see 3 rectangle on the canvas. How can I achieve this?
I found this code in sandbox and added a onmousedown handleclick function but have no idea what to do next
any help is much appreciated
import React, { Component } from "react";
import Konva from "konva";
import { render } from "react-dom";
import { Stage, Layer, Rect, Text } from "react-konva";
class App extends Component {
state = {
cursor: {
x: null,
y: null
}
};
handleClick = (e) => {
alert("mouseclicked");
};
handleMouseMove = (e) => {
var stage = e.currentTarget;
stage = this.stageRef.getStage();
stage = e.target.getStage();
this.setState({
cursor: stage.getPointerPosition()
});
};
render() {
const text = `cursor position : ${this.state.cursor.x}, ${this.state.cursor.y}`;
return (
<Stage
onMouseDown={this.handleClick}
width={window.innerWidth}
height={window.innerHeight}
onMouseMove={this.handleMouseMove}
ref={(ref) => {
this.stageRef = ref;
}}
>
<Layer>
<Text text={text} x={50} y={100} fontSize={20} />
</Layer>
</Stage>
);
}
}
render(<App />, document.getElementById("root"));