Skip to Content
Svelte Flow 2 is out! Read the announcement →
ReferenceTypes

OnNodesChange

This type is used for typing the onnodeschange handler.

export type OnNodesChange<NodeType extends Node = Node> = (changes: NodeChangeset<NodeType>) => void;

Fields

Parameters:
NameTypeDefault
changesNodeChangeset<NodeType>
Returns:
void

Usage

This type accepts a generic type argument of custom node types. See this section in our TypeScript guide for more information.

onnodeschange is called with a NodeChangeset before Svelte Flow applies the changes. You can inspect or edit the changeset inside the handler, and Svelte Flow applies whatever is left afterwards:

const onnodeschange: OnNodesChange = (changes) => { // ignore all changes for this node changes.removeForNode('locked-node'); };

If you want to apply the changes yourself, use applyTo() and call clear() afterwards, so that Svelte Flow doesn’t apply them a second time:

const onnodeschange: OnNodesChange = (changes) => { nodes = changes.applyTo(nodes); changes.clear(); };