I am currently using react and manage a global state with reactn (https://github.com/charlesStover/reactn).
I have to work with "SVG" and be able to make diagrams in the future. I would like for each rectangle that I create, and update the x and y coordinates.
my rectangles are stored in a global state => index.js
SetGlobal({rectangles : []})
I just need to set the array rectangles with indexes of the current rectangle without going through the copy of the whole array
const allRectangles = [...rectangles];
allRectangles[index].x = allRectangles[index].x - diffX;
allRectangles[index].y = allRectangles[index].y - diffY;
allRectangles[index].cercle1.x = allRectangles[index].cercle1.x - diffX;
allRectangles[index].cercle1.y = allRectangles[index].cercle1.y - diffY;
allRectangles[index].cercle2.x = allRectangles[index].cercle2.x - diffX;
allRectangles[index].cercle2.y = allRectangles[index].cercle2.y - diffY;
allRectangles[index].coords.x = e.pageX;
allRectangles[index].coords.y = e.pageY;
setRectangles(allRectangles);
I have to do this kind of exercise but with a global state https://codesandbox.io/s/0xo7y0wolv
I do not know if I made myself understood, it's still new to me.