applyNodeChanges()
applyNodeChanges has been removed. onNodesChange now
receives a NodeChangeset instead of a plain NodeChange[]
array — call changes.applyTo(nodes) on it directly instead of importing this util.
Old API
import { useState, useCallback } from 'react';
import { ReactFlow, applyNodeChanges } from '@xyflow/react';
export default function Flow() {
const [nodes, setNodes] = useState([]);
const [edges, setEdges] = useState([]);
const onNodesChange = useCallback(
(changes) => {
setNodes((oldNodes) => applyNodeChanges(changes, oldNodes));
},
[setNodes],
);
return (
<ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} />
);
}New API
import { useState, useCallback } from 'react';
import { ReactFlow } from '@xyflow/react';
export default function Flow() {
const [nodes, setNodes] = useState([]);
const [edges, setEdges] = useState([]);
const onNodesChange = useCallback(
(changes) => {
setNodes((oldNodes) => changes.applyTo(oldNodes));
},
[setNodes],
);
return (
<ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} />
);
}Notes
- If you don’t need any custom behavior, the
useNodesStatehook conveniently wrapschanges.applyTo()and React’suseStatehook for you and might be simpler to use. - See
NodeChangesetfor the full API (reading changes by type or by node, editing before applying, etc.).