From 0185162052069d49ad26e23a8d7675722c5877c8 Mon Sep 17 00:00:00 2001 From: Heising <1148488607@qq.com> Date: Sun, 21 Jul 2024 19:13:57 +0800 Subject: [PATCH 1/2] fix(TagInput): onDragSort capture context error caused by useRef --- src/hooks/useDragSorter.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/useDragSorter.tsx b/src/hooks/useDragSorter.tsx index 4a3103dc0b..566974466a 100644 --- a/src/hooks/useDragSorter.tsx +++ b/src/hooks/useDragSorter.tsx @@ -1,4 +1,4 @@ -import { useCallback, useRef, useState } from 'react'; +import { useCallback, useState } from 'react'; interface DragSortProps { sortOnDraggable: boolean; @@ -37,7 +37,6 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { const [isDropped, setIsDropped] = useState(null); const [startInfo, setStartInfo] = useState({ nodeX: 0, nodeWidth: 0, mouseX: 0 }); - const onDragSortRef = useRef(onDragSort); const onDragOver = useCallback( (e, index, record: T) => { e.preventDefault(); @@ -64,7 +63,7 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { if (!overlap) return; } - onDragSortRef.current?.({ + onDragSort({ currentIndex: draggingIndex, current: dragStartData, target: record, @@ -80,6 +79,7 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { startInfo.nodeWidth, startInfo.mouseX, startInfo.nodeX, + onDragSort, ], ); From 1a1821ff1386613d7dcf64b310fa984c3611fdb9 Mon Sep 17 00:00:00 2001 From: HaixingOoO <974758671@qq.com> Date: Wed, 31 Jul 2024 22:36:08 +0800 Subject: [PATCH 2/2] fix(usedragsorter): usage useEventCallback --- src/hooks/useDragSorter.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hooks/useDragSorter.tsx b/src/hooks/useDragSorter.tsx index 566974466a..4f51fe8991 100644 --- a/src/hooks/useDragSorter.tsx +++ b/src/hooks/useDragSorter.tsx @@ -1,4 +1,5 @@ import { useCallback, useState } from 'react'; +import useEventCallback from './useEventCallback'; interface DragSortProps { sortOnDraggable: boolean; @@ -36,6 +37,7 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { const [dragStartData, setDragStartData] = useState(null); const [isDropped, setIsDropped] = useState(null); const [startInfo, setStartInfo] = useState({ nodeX: 0, nodeWidth: 0, mouseX: 0 }); + const onDragSortEvent = useEventCallback(onDragSort); const onDragOver = useCallback( (e, index, record: T) => { @@ -63,7 +65,7 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { if (!overlap) return; } - onDragSort({ + onDragSortEvent({ currentIndex: draggingIndex, current: dragStartData, target: record, @@ -79,7 +81,7 @@ function useDragSorter(props: DragSortProps): DragSortInnerProps { startInfo.nodeWidth, startInfo.mouseX, startInfo.nodeX, - onDragSort, + onDragSortEvent, ], );