Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TagInput): onDragSort capture context error caused by useRef #3003

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading