Skip to content

Commit c52f435

Browse files
committed
chore: remove unneeded useRef
1 parent fac0ff0 commit c52f435

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/client/Editor.tsx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import { Editor as MonacoEditor } from "@monaco-editor/react";
2+
import {
3+
CheckIcon,
4+
ChevronDownIcon,
5+
CopyIcon,
6+
FileJsonIcon,
7+
SettingsIcon,
8+
ZapIcon,
9+
} from "lucide-react";
10+
import { type FC, useEffect, useState } from "react";
111
import { Button } from "@/client/components/Button";
212
import {
313
DropdownMenu,
@@ -13,21 +23,11 @@ import {
1323
TooltipContent,
1424
TooltipTrigger,
1525
} from "@/client/components/Tooltip";
16-
import { useTheme } from "@/client/contexts/theme";
17-
import { snippets, type SnippetFunc } from "@/client/snippets";
18-
import { cn } from "@/utils/cn";
19-
import { Editor as MonacoEditor } from "@monaco-editor/react";
20-
import {
21-
CheckIcon,
22-
ChevronDownIcon,
23-
CopyIcon,
24-
FileJsonIcon,
25-
SettingsIcon,
26-
ZapIcon,
27-
} from "lucide-react";
28-
import { type FC, useEffect, useRef, useState } from "react";
2926
import { useEditor } from "@/client/contexts/editor";
27+
import { useTheme } from "@/client/contexts/theme";
28+
import { type SnippetFunc, snippets } from "@/client/snippets";
3029
import type { ParameterWithSource } from "@/gen/types";
30+
import { cn } from "@/utils/cn";
3131

3232
type EditorProps = {
3333
code: string;
@@ -42,9 +42,6 @@ export const Editor: FC<EditorProps> = ({ code, setCode, parameters }) => {
4242
const [tab, setTab] = useState(() => "code");
4343

4444
const [codeCopied, setCodeCopied] = useState(() => false);
45-
const copyTimeoutId = useRef<ReturnType<typeof setTimeout> | undefined>(
46-
undefined,
47-
);
4845

4946
const onCopy = () => {
5047
navigator.clipboard.writeText(code);
@@ -65,13 +62,11 @@ export const Editor: FC<EditorProps> = ({ code, setCode, parameters }) => {
6562
return;
6663
}
6764

68-
clearTimeout(copyTimeoutId.current);
69-
70-
copyTimeoutId.current = setTimeout(() => {
65+
const copyTimeoutId = setTimeout(() => {
7166
setCodeCopied(() => false);
7267
}, 1000);
7368

74-
return () => clearTimeout(copyTimeoutId.current);
69+
return () => clearTimeout(copyTimeoutId);
7570
}, [codeCopied]);
7671

7772
return (

0 commit comments

Comments
 (0)