Reference
useNodes()

useNodes

Source on GitHub (opens in a new tab)

This hook returns an array of the current nodes. Components that use this hook will re-render whenever any node changes, including when a node is selected or moved.

import { useNodes } from 'reactflow';
 
export default function () {
  const nodes = useNodes();
 
  return <div>There are currently {nodes.length} nodes!</div>;
}

Signature

#Returns
Node<T>[]
An array of all nodes currently in the flow.

Notes

  • Relying on useNodes unecessarily can be a common cause of performance issues. Whenever any node changes, this hook will cause the component to re-render. Often we actually care about something more specific, like when the number of nodes changes: where possible try to use useStore instead.