Helper Functions

If you want to remove a node or connect two nodes with each other you need to pass a function to onElementsRemove and onConnect. In order to simplify this process there are some helper functions you can use:
import ReactFlow, { isNode, isEdge, removeElements, addEdge } from 'react-flow-renderer';


Returns true if the passed element is an edge.
isEdge = (element: Node | Edge): element is Edge


Returns true if the passed element is a node.
isNode = (element: Node | Edge): element is Node


Returns an array of elements without the ones from elementsToRemove. It also removes all incoming/outgoing edges if you just pass one or multiple nodes.
removeElements = (elementsToRemove: Elements, elements: Elements): Elements


Returns an array with elements with the added edge.
addEdge = (edgeParams: Edge, elements: Elements): Elements


Returns all direct child nodes of the passed node.
getOutgoers = (node: Node, elements: Elements): Node[]


Returns all direct incoming nodes of the passed node.
getIncomers = (node: Node, elements: Elements): Node[]


Returns all edges that are connected to the passed nodes.
getConnectedEdges = (nodes: Node[], edges: Edge[]): Edge[]
You can use these function as seen in this example or use your own ones.
Edit this page