Skip to content

duplicateNodes

duplicateNodes(nodes, ids, options?): NodeGraphNode[]

Defined in: src/components/editor/NodeGraph/nodeGraphActions.ts:58

Clone the nodes whose ids are listed in ids, offsetting each copy. Pure — returns only the new node objects (not merged into the source list), so callers stay in control of ordering and selection:

const copies = duplicateNodes(nodes, selection.nodes);
setNodes(prev => [...prev, ...copies]);
setSelection({ nodes: copies.map(n => n.id), edges: [], groups: [] });

Edges between duplicated nodes are intentionally not copied — wire that in at the call site if your editor needs it.

Parameters

nodes

readonly NodeGraphNode[]

ids

readonly string[]

options?

DuplicateNodesOptions

Returns

NodeGraphNode[]