The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/components/GrotNotFound/useMousePosition.ts

29 lines
853 B

import { throttle } from 'lodash';
import { useState, useEffect } from 'react';
interface MousePosition {
x: number | null;
y: number | null;
}
// For performance reasons, we throttle the mouse position updates
const DEFAULT_THROTTLE_INTERVAL_MS = 50;
const useMousePosition = (throttleInterval = DEFAULT_THROTTLE_INTERVAL_MS) => {
const [mousePosition, setMousePosition] = useState<MousePosition>({ x: null, y: null });
useEffect(() => {
const updateMousePosition = throttle((event: MouseEvent) => {
setMousePosition({ x: event.clientX, y: event.clientY });
}, throttleInterval);
window.addEventListener('mousemove', updateMousePosition);
return () => {
window.removeEventListener('mousemove', updateMousePosition);
};
}, [throttleInterval]);
return mousePosition;
};
export default useMousePosition;