Skip to content

Commit

Permalink
fix debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito committed Aug 14, 2024
1 parent f373bb0 commit a639b53
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/ui/components/utils/TooltipProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';
import { useDebouncedState, useMediaQuery } from '@rocket.chat/fuselage-hooks';
import type { ReactNode } from 'react';
import React, {
useEffect,
useMemo,
useRef,
memo,
useCallback,
useState,
} from 'react';
import { useEffect, useMemo, useRef, memo, useCallback } from 'react';

import { TooltipComponent } from './TooltipComponent';
import { TooltipContext } from './TooltipContext';
Expand All @@ -21,7 +14,7 @@ const TooltipProvider = ({ children }: TooltipProviderProps) => {
const lastAnchor = useRef<HTMLElement | null>(null);
const hasHover = !useMediaQuery('(hover: none)');

const [tooltip, setTooltip] = useState<ReactNode>(null);
const [tooltip, setTooltip] = useDebouncedState<ReactNode>(null, 300);

const restoreTitle = useCallback(
(previousAnchor: HTMLElement | undefined): void => {
Expand Down Expand Up @@ -67,7 +60,7 @@ const TooltipProvider = ({ children }: TooltipProviderProps) => {
close: (): void => {
const previousAnchor = lastAnchor.current;
setTooltip(null);
lastAnchor.current = undefined;
lastAnchor.current = null;
previousAnchor && restoreTitle(previousAnchor);
},
dismiss: (): void => {
Expand Down

0 comments on commit a639b53

Please sign in to comment.