Position Updates of Multiple Nodes on Drag Stop #1240
Unanswered
abbieschenk
asked this question in
Q&A
Replies: 2 comments
-
|
Bump! Any updates on this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hi, Example: import {
useStoreApi,
} from "@xyflow/react"; const store = useStoreApi();
const onNodeDragStop = useCallback(
(_: React.MouseEvent, node: Node) => {
// Get selected nodes from store
const state = store.getState();
const selectedNodeIds = state.nodes.filter((n: any) => n.selected).map((n: any) => n.id);
console.log("selectedNodes", selectedNodeIds);
},
[store]
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I need to save / persist the position of Nodes with an API call after they are moved around. This works for one node by using "onNodeDragStop(event, node)."
It doesn't work when selecting multiple nodes with Cmd and then dragging them all around, as the onNodeDragStop event is only called on the first selected node — note I don't mean shift + dragging around the nodes and moving them that way, as I can get that working fine.
I tried to fix this by using
const selectedElements = useStoreState(actions => actions.selectedElements);as per Issue #492. But these elements do not have an updated position, as it appears they only get initialized once and then not updated.I was wondering if there is a way to get all the updated positions of all nodes that have moved on a drag event. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions