Skip to Content
✨ Svelte Flow 1.0 is here! Rewritten for Svelte 5 with many new features and improvements.
ReferenceHooksuseOnSelectionChange()

useOnSelectionChange()

Source on GitHub 

This hook lets you listen for changes to both node and edge selection. As the name implies, the callback you provide will be called whenever the selection of either nodes or edges changes.

Component.svelte
<script> import { useOnSelectionChange } from '@xyflow/svelte'; let selectedNodes = $state.raw([]); let selectedEdges = $state.raw([]); useOnSelectionChange(({ nodes, edges }) => { selectedNodes = nodes.map((node) => node.id); selectedEdges = edges.map((edge) => edge.id); }); </script> <div> <p>Selected nodes: {selectedNodes.join(', ')}</p> <p>Selected edges: {selectedEdges.join(', ')}</p> </div>

Signature

Parameters:
NameTypeDefault
onselectionchangeOnSelectionChange
Returns:
void

Notes

Last updated on