From 833dc694754e882d2f5b78d3f96e9c3dc337cae2 Mon Sep 17 00:00:00 2001 From: unrenamed Date: Fri, 8 Nov 2024 13:07:45 +0200 Subject: [PATCH 1/4] fix: adjust useEffect dependencies to prevent lint warnings in button components --- .../components/dashboard/copy-button.tsx | 16 +++++++++------ .../components/dashboard/visible-button.tsx | 13 +++++++----- apps/www/components/copy-button.tsx | 20 +++++++++++-------- apps/www/components/ui/copy-code-button.tsx | 15 ++++++++++---- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/apps/dashboard/components/dashboard/copy-button.tsx b/apps/dashboard/components/dashboard/copy-button.tsx index 906888f232..402d88d001 100644 --- a/apps/dashboard/components/dashboard/copy-button.tsx +++ b/apps/dashboard/components/dashboard/copy-button.tsx @@ -15,13 +15,17 @@ async function copyToClipboardWithMeta(value: string, _meta?: Record { - setTimeout(() => { - setHasCopied(false); + if (!copied) { + return; + } + const timer = setTimeout(() => { + setCopied(false); }, 2000); - }, [hasCopied]); + return () => clearTimeout(timer); + }, [copied]); return ( ); } diff --git a/apps/dashboard/components/dashboard/visible-button.tsx b/apps/dashboard/components/dashboard/visible-button.tsx index 8407bd1821..ac7d863e12 100644 --- a/apps/dashboard/components/dashboard/visible-button.tsx +++ b/apps/dashboard/components/dashboard/visible-button.tsx @@ -1,7 +1,6 @@ -import * as React from "react"; - import { cn } from "@/lib/utils"; import { Eye, EyeOff } from "lucide-react"; +import { useEffect } from "react"; type VisibleButtonProps = React.HTMLAttributes & { isVisible: boolean; @@ -14,11 +13,15 @@ export function VisibleButton({ setIsVisible, ...props }: VisibleButtonProps) { - React.useEffect(() => { - setTimeout(() => { + useEffect(() => { + if (!isVisible) { + return; + } + const timer = setTimeout(() => { setIsVisible(false); }, 10000); - }, [isVisible]); + return () => clearTimeout(timer); + }, [setIsVisible, isVisible]); return (