Skip to content

Commit 22fc17c

Browse files
add debouce
1 parent dbd4a1f commit 22fc17c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

frontend/routes/@[scope]/(_islands)/ScopeMemberLeave.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
21
import TbArrowRightFromArc from "@preact-icons/tb/TbArrowRightFromArc";
32
import { useSignal } from "@preact/signals";
3+
import { useEffect } from "preact/hooks";
44

55
export function ScopeMemberLeave({
66
userId,
@@ -16,6 +16,14 @@ export function ScopeMemberLeave({
1616
const scopeInput = useSignal("");
1717
const error = useSignal(true);
1818

19+
useEffect(() => {
20+
const handler = setTimeout(() => {
21+
validate();
22+
}, 500);
23+
24+
return clearTimeout(handler);
25+
}, [scopeInput.value]);
26+
1927
const validate = () => {
2028
error.value = isLastAdmin ||
2129
(scopeInput.value !== scopeName && scopeInput.value.length > 0) ||
@@ -53,7 +61,6 @@ export function ScopeMemberLeave({
5361
value={scopeInput.value}
5462
onInput={(e) => {
5563
scopeInput.value = (e.target as HTMLInputElement).value;
56-
validate();
5764
}}
5865
placeholder="Scope name"
5966
/>

0 commit comments

Comments
 (0)