applyNodeChanges()
Source on GitHub (opens in a new tab)
Various events on the <ReactFlow />
component can produce an
NodeChange
that describes how to update the edges of your
flow in some way. If you don't need any custom behaviour, this util can be used to
take an array of these changes and apply them to your edges.
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} />
);
}
Signature
Name | Type |
---|---|
#Params |
|
# changes | |
# nodes | Node[] |
#Returns |
|
Node[] |
Notes
- If you don't need any custom behaviour, the
useNodesState
hook conviniently wraps this util and React'suseState
hook for you and might be simpler to use.