diff --git a/client/src/components/Planner/DayPlanSidebar.tsx b/client/src/components/Planner/DayPlanSidebar.tsx index 10cf92589..40d0a3a68 100644 --- a/client/src/components/Planner/DayPlanSidebar.tsx +++ b/client/src/components/Planner/DayPlanSidebar.tsx @@ -373,7 +373,7 @@ function useDayPlanSidebar(props: DayPlanSidebarProps) { } document.addEventListener('dragend', cleanup) return () => document.removeEventListener('dragend', cleanup) - }, []) + }, [setDraggingId, setDropTargetKey, setDragOverDayId]) // Initialize missing transport positions outside of render to avoid setState-during-render // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/client/src/components/Planner/useDayPlanDragState.ts b/client/src/components/Planner/useDayPlanDragState.ts index 1e81387f5..51af8b614 100644 --- a/client/src/components/Planner/useDayPlanDragState.ts +++ b/client/src/components/Planner/useDayPlanDragState.ts @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState, type MutableRefObject } from 'react'; +import { useCallback, useEffect, useRef, useState, type MutableRefObject } from 'react'; /** A stop's or a day's id, as the day plan's drag handlers pass them around. */ type DragKey = string | number | null; @@ -27,14 +27,15 @@ export function useDayPlanDragState(dragDataRef: MutableRefObject) { const dropTargetRef = useRef(null); const [dragOverDayId, setDragOverDayId] = useState(null); - const setDraggingId = (id: DragKey) => { + // Stable, so the sidebar's listeners that call them are set up once. + const setDraggingId = useCallback((id: DragKey) => { if (id != null) setHasDragged(true); setDraggingIdState(id); - }; - const setDropTargetKey = (key: string | null) => { + }, []); + const setDropTargetKey = useCallback((key: string | null) => { dropTargetRef.current = key; setDropTargetKeyState(key); - }; + }, []); useEffect(() => { if (!draggingId && !dropTargetKey && !dragOverDayId) return;