logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • start
    • Introduction
    • Quick Start
  • component
    • XFlowGraph Canvas
    • Background
    • Grid
    • Clipboard Copy and Paste
    • History Undo Redo
    • Minimap
    • Snapline Alignment Lines
    • Transform
    • Control Controller
  • Hook
    • useGraphInstance
    • useGraphStore
    • useGraphEvent
    • useDnd
    • useClipboard
    • useExport
    • useHistory
    • useKeyboard
  • Store

useGraphStore

Previous
useGraphInstance
Next
useGraphEvent

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Get the current canvas store and a Hook to change the store.

Basic Usage

const nodes = useGraphStore((state) => state.nodes);

Using useGraphStore allows for easy CRUD (Create, Read, Update, Delete) operations on the canvas data. Below is a simple example of adding and removing nodes using useGraphStore.

API

useGraphStore<T, U>(selector: (state: U) => T): U

Return Value

ParameterDescriptionTypeDefault Value
UActions of the canvas storeOptions-

Parameters

ParameterDescriptionTypeDefault Value
selectorFunction to get the store's actions(state: Options) => Options-

Options parameters are as follows

ParameterDescriptionTypeDefault Value
nodesAll nodes in the canvasNodeOptions[]-
edgesAll edges in the canvasEdgeOptions[]-
changeListStore operation records(init | addNodes | removeNodes | updateNode | addEdges | removeEdges | updateEdge )[]-
initDataInitialize data(data: {nodes: NodeOptions[], edges: EdgeOptions[] }, options?: {silent?: boolean}) => void-
addNodesAdd nodes(ns: NodeOptions[], options?: {silent?: boolean}) => void-
removeNodesRemove nodes(ids: string[], options?: {silent?: boolean}) => void-
updateNodeUpdate node(id: string, data: UpdateNodeDataOrFn, options?: {silent?: boolean}) => void-
addEdgesAdd edges(es: EdgeOptions[], options?: {silent?: boolean}) => void-
removeEdgesRemove edges(ids: string[], options?: {silent?: boolean}) => void-
updateEdgeUpdate edge(id: string, data: UpdateEdgeDataOrFn, options?: {silent?: boolean}) => void-
clearChangeListClear operation records() => void-