Skip to Content
React Flow 13 is here! Read the announcement →
ReferenceUtils

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.

Source on GitHub 

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 useNodesState hook conveniently wraps changes.applyTo() and React’s useState hook for you and might be simpler to use.
  • See NodeChangeset for the full API (reading changes by type or by node, editing before applying, etc.).