Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 271x 271x 271x 171x 171x 171x 271x 20x 20x 9x 9x 271x | import { useCallback, useEffect, useRef } from "react";
export default function useStopHighlight(onChange?: (stopId?: number) => void) {
const hoveredStop = useRef<number | undefined>(undefined);
const focusedStop = useRef<number | undefined>(undefined);
const clearHighlight = useCallback(() => {
hoveredStop.current = undefined;
focusedStop.current = undefined;
onChange?.();
}, [onChange]);
useEffect(() => clearHighlight, [clearHighlight]);
function hoverStop(stopId?: number) {
hoveredStop.current = stopId;
onChange?.(stopId ?? focusedStop.current);
}
function focusStop(stopId?: number) {
focusedStop.current = stopId;
onChange?.(hoveredStop.current ?? stopId);
}
return { clearHighlight, focusStop, hoverStop };
}
|