Answer the question
In order to leave comments, you need to log in
How to create an element in React on mouse click?
There is an element inside which the addPoint function is called by clicking on the button.
the error is "TypeError: mouseCoordsLayer.createElement is not a function"
addPoint = (e) => {
e.preventDefault();
e.stopPropagation();
const mouseCoordsLayer = this.pageRefs.current;
const coordinate = [];
console.log('click1');
let point = mouseCoordsLayer.createElement("div");
coordinate.push([this.MouseCoords.getX(e), this.MouseCoords.getY(e)]);
}
};
Answer the question
In order to leave comments, you need to log in
1. The createElement method is implemented on the document object .
2. It is better not to use such methods of creating elements in React development. Work with data and render components based on it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question