Merge pull request #4725 from xyflow/feat/use-handle-connection
add `useNodeConnections`, deprecate `useHandleConnections`
This commit is contained in:
@@ -49,7 +49,7 @@ import NodeToolbar from '../examples/NodeToolbar';
|
||||
import UseConnection from '../examples/UseConnection';
|
||||
import UseNodesInitialized from '../examples/UseNodesInit';
|
||||
import UseNodesData from '../examples/UseNodesData';
|
||||
import UseHandleConnections from '../examples/UseHandleConnections';
|
||||
import UseNodeConnections from '../examples/UseNodeConnections';
|
||||
import AddNodeOnEdgeDrop from '../examples/AddNodeOnEdgeDrop';
|
||||
import DevTools from '../examples/DevTools';
|
||||
import Redux from '../examples/Redux';
|
||||
@@ -313,9 +313,9 @@ const routes: IRoute[] = [
|
||||
component: UseReactFlow,
|
||||
},
|
||||
{
|
||||
name: 'useHandleConnections',
|
||||
path: 'usehandleconnections',
|
||||
component: UseHandleConnections,
|
||||
name: 'useNodeConnections',
|
||||
path: 'usenodeconnections',
|
||||
component: UseNodeConnections,
|
||||
},
|
||||
{
|
||||
name: 'useNodesData',
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { memo, FC, useEffect, useCallback } from 'react';
|
||||
import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react';
|
||||
import { Handle, Position, NodeProps, useNodeConnections, Connection, HandleProps } from '@xyflow/react';
|
||||
|
||||
function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) {
|
||||
const onConnect = useCallback(
|
||||
@@ -11,9 +11,9 @@ function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string
|
||||
(connections: Connection[]) => console.log('onDisconnect handler, node id:', nodeId, connections),
|
||||
[nodeId]
|
||||
);
|
||||
const connections = useHandleConnections({
|
||||
const connections = useNodeConnections({
|
||||
type: handleProps.type,
|
||||
id: handleProps.id,
|
||||
handleId: handleProps.id,
|
||||
onConnect,
|
||||
onDisconnect,
|
||||
});
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { memo, FC, useEffect, useCallback } from 'react';
|
||||
import { Handle, Position, NodeProps, useHandleConnections, Connection, HandleProps } from '@xyflow/react';
|
||||
import { Handle, Position, NodeProps, useNodeConnections, Connection, HandleProps } from '@xyflow/react';
|
||||
|
||||
function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string }) {
|
||||
const onConnect = useCallback(
|
||||
@@ -14,9 +14,9 @@ function CustomHandle({ nodeId, ...handleProps }: HandleProps & { nodeId: string
|
||||
},
|
||||
[nodeId]
|
||||
);
|
||||
const connections = useHandleConnections({
|
||||
const connections = useNodeConnections({
|
||||
type: handleProps.type,
|
||||
id: handleProps.id,
|
||||
handleId: handleProps.id,
|
||||
onConnect,
|
||||
onDisconnect,
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
import { memo } from 'react';
|
||||
import { Handle, Position, useHandleConnections, useNodesData } from '@xyflow/react';
|
||||
import { Handle, Position, useNodeConnections, useNodesData } from '@xyflow/react';
|
||||
import { isTextNode, type MyNode } from '.';
|
||||
|
||||
function ResultNode() {
|
||||
const connections = useHandleConnections({
|
||||
const connections = useNodeConnections({
|
||||
type: 'target',
|
||||
});
|
||||
const nodesData = useNodesData<MyNode>(connections.map((connection) => connection.source));
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { memo, useEffect } from 'react';
|
||||
import { Position, NodeProps, useReactFlow, Handle, useHandleConnections, useNodesData } from '@xyflow/react';
|
||||
import { Position, NodeProps, useReactFlow, Handle, useNodeConnections, useNodesData } from '@xyflow/react';
|
||||
import { isTextNode, type TextNode, type MyNode } from '.';
|
||||
|
||||
function UppercaseNode({ id }: NodeProps) {
|
||||
const { updateNodeData } = useReactFlow();
|
||||
const connections = useHandleConnections({
|
||||
const connections = useNodeConnections({
|
||||
type: 'target',
|
||||
});
|
||||
const nodesData = useNodesData<MyNode>(connections[0]?.source);
|
||||
|
||||
Reference in New Issue
Block a user