Guides -> Custom Nodes -> Using Multiple Handles

master
Jason Zhu 2023-05-29 22:02:17 +10:00
parent 4b962e81d6
commit 89b66be215
1 changed files with 27 additions and 9 deletions

View File

@ -1,16 +1,17 @@
import { useState, useCallback } from 'react'; import { useCallback, useState } from 'react';
import ReactFlow, { import ReactFlow, {
Background, addEdge,
Controls,
applyEdgeChanges, applyEdgeChanges,
applyNodeChanges, applyNodeChanges,
addEdge, Background,
Node,
Edge,
NodeChange,
EdgeChange,
Connection, Connection,
Controls,
Edge,
EdgeChange,
Node,
NodeChange,
NodeTypes, NodeTypes,
Position,
} from 'reactflow'; } from 'reactflow';
import TextUpdaterNode from './components/TextUpdaterNode'; import TextUpdaterNode from './components/TextUpdaterNode';
@ -22,7 +23,10 @@ const rfStyle = {
backgroundColor: '#B8CEFF', backgroundColor: '#B8CEFF',
}; };
const initialEdges: Edge[] = []; const initialEdges: Edge[] = [
{ id: 'edge-1', source: 'node-1', target: 'node-2', sourceHandle: 'a' },
{ id: 'edge-2', source: 'node-1', target: 'node-3', sourceHandle: 'b' },
];
const initialNodes: Node[] = [ const initialNodes: Node[] = [
{ {
@ -31,6 +35,20 @@ const initialNodes: Node[] = [
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
data: { value: 123 }, data: { value: 123 },
}, },
{
id: 'node-2',
type: 'output',
targetPosition: Position.Top,
position: { x: 0, y: 200 },
data: { label: 'node 2' },
},
{
id: 'node-3',
type: 'output',
targetPosition: Position.Top,
position: { x: 200, y: 200 },
data: { label: 'node 3' },
},
]; ];
const nodeTypes: NodeTypes = { textUpdater: TextUpdaterNode }; const nodeTypes: NodeTypes = { textUpdater: TextUpdaterNode };