Useful hooks for reactflow
npm install reactflow-hooksUseful hooks for ReactFlow
A version of reactflow's useNode hook that throws an error if not called within a node instead of returning null.
``typescript`
function useAssertNodeId(): string | never;
A hook that returns the current node without subscribing to changes.
`typescript`
function useNode
A hook that returns actions that can be performed on the current node.
`typescript
interface NodeActions {
deleteNode: () => void;
}
function useNodeActions
`
A hook that subscribes to changes in the current node's state.
`typescript`
function useNodeState
selector?: (node: Node
equalityFn?: (a: U, b: U) => boolean
): U | never;
A hook that subscribes specifically to changes in the current node's data.
`typescript`
function useNodeData
selector?: (data: T) => U,
equalityFn?: (a: U, b: U) => boolean
): U | never;
A hook that returns the ingoing edges of the current node.
`typescript`
function useIngressEdges
A hook that returns the outgoing edges of the current node.
`typescript`
function useEgressEdges
A hook that returns the source nodes of the current node, i.e. the nodes that have an outgoing edge to the current node.
`typescript`
function useSourceNodes
A hook that returns the target nodes of the current node, i.e. the nodes that have an ingoing edge from the current node.
`typescript`
function useTargetNodes
A subscribing hook that returns whether a given input handle of the current node is connected.
`typescript`
function useIsInputConnected(inputId: string): boolean | never;
A subscribing hook that returns whether a given output handle of the current node is connected.
`typescript`
function useIsOutputConnected(outputId: string): boolean | never;
A subscribing hook that returns whether a given handle of the current node is connected.
`typescript`
function useIsHandleConnected(handleId: string, handleType: HandleType): boolean | never;
`bash`
npm install reactflow-hooks
`bash``
bun install reactflow-hooks