Skip to content

Commit 1af87a2

Browse files
add debouce
1 parent dbd4a1f commit 1af87a2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
22
import TbArrowRightFromArc from "@preact-icons/tb/TbArrowRightFromArc";
33
import { useSignal } from "@preact/signals";
4+
import { useEffect } from "preact/hooks";
45

56
export function ScopeMemberLeave({
67
userId,
@@ -16,6 +17,14 @@ export function ScopeMemberLeave({
1617
const scopeInput = useSignal("");
1718
const error = useSignal(true);
1819

20+
useEffect(() => {
21+
const handler = setTimeout(() => {
22+
validate();
23+
}, 500);
24+
25+
return clearTimeout(handler);
26+
}, [scopeInput.value]);
27+
1928
const validate = () => {
2029
error.value = isLastAdmin ||
2130
(scopeInput.value !== scopeName && scopeInput.value.length > 0) ||
@@ -53,7 +62,6 @@ export function ScopeMemberLeave({
5362
value={scopeInput.value}
5463
onInput={(e) => {
5564
scopeInput.value = (e.target as HTMLInputElement).value;
56-
validate();
5765
}}
5866
placeholder="Scope name"
5967
/>

0 commit comments

Comments
 (0)