useSetSelection
useSetSelection(): (
selection) =>boolean
Returns a function that replaces the selection with the given nodes and edges, as a click does
for one element: a group’s selection box goes too, and a held multi-selection key changes
nothing. An empty call clears the selection. It returns false and changes nothing when the
canvas lacks any of the ids. Stable across renders.
The canvas learns of a node on its next render, so a node added in the same tick counts as
missing; give it selected: true as you add it instead. Unlike a click, it also selects an
element the person cannot select, such as one with selectable: false.
Use it for a control outside the canvas that leads to an element, such as a notification’s
button. Must be called from a descendant of <WorkflowBuilder.Root>, which holds the canvas’s
React Flow store.
Returns
Section titled “Returns”(selection) => boolean
Example
Section titled “Example”function GoToNode({ nodeId }: { nodeId: string }) { const setSelection = useSetSelection(); return <button onClick={() => setSelection({ nodeIds: [nodeId] })}>Show</button>;}