From 7a652fc17c61a16057d0207cf9189834d90a24bd Mon Sep 17 00:00:00 2001 From: moklick Date: Sun, 5 Feb 2023 21:58:30 +0100 Subject: [PATCH] chore(connections): get fresh ref of onConnectEnd --- packages/core/src/components/Handle/handler.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/src/components/Handle/handler.ts b/packages/core/src/components/Handle/handler.ts index 5c54118f..6c484edb 100644 --- a/packages/core/src/components/Handle/handler.ts +++ b/packages/core/src/components/Handle/handler.ts @@ -2,7 +2,7 @@ import type { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } fro import { StoreApi } from 'zustand'; import { getHostForElement, calcAutoPan, getEventPosition } from '../../utils'; -import type { OnConnect, HandleType, ReactFlowState, Connection, ConnectionStatus } from '../../types'; +import type { OnConnect, HandleType, ReactFlowState, Connection } from '../../types'; import { pointToRendererPoint, rendererPointToPoint } from '../../utils/graph'; import { ConnectionHandle, @@ -46,7 +46,6 @@ export function handlePointerDown({ autoPanOnConnect, connectionRadius, onConnectStart, - onConnectEnd, panBy, getNodes, cancelConnection, @@ -159,7 +158,9 @@ export function handlePointerDown({ onConnect?.(connection); } - onConnectEnd?.(event); + // it's important to get a fresh reference from the store here + // in order to get the latest state of onConnectEnd + getState().onConnectEnd?.(event); if (edgeUpdaterType) { onEdgeUpdateEnd?.(event);