Skip to content

Commit

Permalink
fix(TagInput): onDragSort capture context error caused by useRef (#3003)
Browse files Browse the repository at this point in the history
* fix(TagInput): onDragSort capture context error caused by useRef

* fix(usedragsorter): usage useEventCallback

---------

Co-authored-by: HaixingOoO <[email protected]>
  • Loading branch information
Heising and HaixingOoO committed Jul 31, 2024
1 parent 897299d commit 7e41d7a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/hooks/useDragSorter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useRef, useState } from 'react';
import { useCallback, useState } from 'react';
import useEventCallback from './useEventCallback';

interface DragSortProps<T> {
sortOnDraggable: boolean;
Expand Down Expand Up @@ -36,8 +37,8 @@ function useDragSorter<T>(props: DragSortProps<T>): 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 onDragSortRef = useRef(onDragSort);
const onDragOver = useCallback(
(e, index, record: T) => {
e.preventDefault();
Expand All @@ -64,7 +65,7 @@ function useDragSorter<T>(props: DragSortProps<T>): DragSortInnerProps {
if (!overlap) return;
}

onDragSortRef.current?.({
onDragSortEvent({
currentIndex: draggingIndex,
current: dragStartData,
target: record,
Expand All @@ -80,6 +81,7 @@ function useDragSorter<T>(props: DragSortProps<T>): DragSortInnerProps {
startInfo.nodeWidth,
startInfo.mouseX,
startInfo.nodeX,
onDragSortEvent,
],
);

Expand Down

0 comments on commit 7e41d7a

Please sign in to comment.