React Nodes
Previous
Group
Next
Vue Nodes
Loading...
We provide a standalone package @antv/x6-react-shape for rendering nodes with React.
Version compatibility: X6 3.x must use x6-react-shape 3.x. Since 2.0.8, x6-react-shape supports React 18+ only; if your project uses React < 18, lock x6-react-shape to 2.0.8 and use X6 2.x.
import { register } from '@antv/x6-react-shape'const NodeComponent = () => {return (<div className="react-node"><Progress type="circle" percent={30} width={80} /></div>)}register({shape: 'custom-basic-react-node',width: 100,height: 100,component: NodeComponent,})graph.addNode({shape: 'custom-basic-react-node',x: 60,y: 100,})
Similar to HTML, register a node with an effect field—an array of the node’s props. When any listed prop changes, the React component re-renders.
register({shape: 'custom-update-react-node',width: 100,height: 100,effect: ['data'],component: NodeComponent,})const node = graph.addNode({shape: 'custom-update-react-node',x: 60,y: 100,data: {progress: 30,},})setInterval(() => {const { progress } = node.getData<{ progress: number }>()node.setData({progress: (progress + 10) % 100,})}, 1000)
The approach above renders the component directly into the node’s DOM:
import { createRoot, Root } from 'react-dom/client'const root = createRoot(container) // container is the node containerroot.render(component)
This detaches the component from the normal React tree, so it cannot access external Context. Use Portal mode when you need access to app-level context.