Skip to Content
Vue Flow v2 is here and joins xyflow! Read more here →

useVueFlow()

Source on GitHub 

The useVueFlow composable returns the Vue Flow instance: a curated set of actions (setNodes, addEdges, updateNodeData, deleteElements, …), computed getters (getNodes, getEdges, getSelectedNodes, viewport), the viewport helpers (fitView, zoomIn, setCenter, screenToFlowPosition, …), and the on* event hooks (onConnect, onNodeDragStop, onInit, …).

It must run inside a flow provided by <VueFlow />, <VueFlowProvider />, or setupVueFlow() — otherwise it throws.

<script setup lang="ts"> import { useVueFlow } from '@xyflow/vue'; const { fitView, setNodes, onConnect } = useVueFlow(); onConnect((connection) => { console.log('new connection', connection); }); </script>

Signature

Parameters:

This function does not accept any parameters.

Returns:
VueFlowInstance<NodeType, EdgeType>

the VueFlow instance for the current context

Notes

  • useVueFlow returns the curated instance, not raw state. To read the reactive store directly (e.g. nodeLookup, transform), use useVueFlowStore() — optionally with storeToRefs().
  • Several things that are standalone hooks in React/Svelte Flow are methods on this instance in Vue Flow — e.g. updateNodeInternals, getViewport/setViewport, and the selection/viewport event hooks (onSelectionChange, onViewportChange).