mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
20 lines
516 B
TypeScript
20 lines
516 B
TypeScript
|
import { useEffect, useState } from 'react';
|
||
|
import useMountedState from 'react-use/lib/useMountedState';
|
||
|
|
||
|
export function useHighlight(focusedNodeId?: string) {
|
||
|
const [highlightId, setHighlightId] = useState<string>();
|
||
|
const mounted = useMountedState();
|
||
|
useEffect(() => {
|
||
|
if (focusedNodeId) {
|
||
|
setHighlightId(focusedNodeId);
|
||
|
setTimeout(() => {
|
||
|
if (mounted()) {
|
||
|
setHighlightId(undefined);
|
||
|
}
|
||
|
}, 500);
|
||
|
}
|
||
|
}, [focusedNodeId, mounted]);
|
||
|
|
||
|
return highlightId;
|
||
|
}
|