Skip to content

Commit 6fce9f5

Browse files
committed
avoid hydration issues rendering the tooltip only on client side
1 parent d677525 commit 6fce9f5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/components/Tooltip/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "../ui/tooltip"
1111

1212
import { useDisclosure } from "@/hooks/useDisclosure"
13+
import { useIsClient } from "@/hooks/useIsClient"
1314

1415
export type TooltipProps = ComponentProps<typeof Popover> & {
1516
content: ReactNode
@@ -24,6 +25,7 @@ const Tooltip = ({
2425
...props
2526
}: TooltipProps) => {
2627
const { isOpen, onOpen, onClose } = useDisclosure()
28+
const isClient = useIsClient()
2729

2830
// Close the popover when the user scrolls.
2931
// This is useful for mobile devices where the popover is open by clicking the
@@ -64,6 +66,12 @@ const Tooltip = ({
6466
}
6567
}
6668

69+
// Avoid rendering on the server since the user can't interact with it and we
70+
// need to use different components depending on the device
71+
if (!isClient) {
72+
return null
73+
}
74+
6775
// Use Popover on mobile devices since the user can't hover
6876
const Component = isMobile() ? Popover : Tooltipcomponent
6977
const Trigger = isMobile() ? PopoverTrigger : TooltipTrigger

0 commit comments

Comments
 (0)