Skip to content

Commit 9f4fcf5

Browse files
committed
Avoid multiple clicks on button
1 parent f7c36f6 commit 9f4fcf5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/shared-components/src/components/button/ButtonWithSpinner.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@ interface Props {
1818
}
1919

2020
const ButtonWithSpinner = ({ children, className, onClick, variant = 'primary', size = 'medium', icon }: Props) => {
21-
const [isSaving, setIsSaving] = useState(false);
21+
const [processing, setProcessing] = useState(false);
2222
async function onClickWithSpinner() {
23-
setIsSaving(true);
24-
try {
25-
await onClick();
26-
} finally {
27-
setIsSaving(false);
23+
if (!processing) {
24+
setProcessing(true);
25+
try {
26+
await onClick();
27+
} finally {
28+
setProcessing(false);
29+
}
2830
}
2931
}
3032
return (
3133
<Button
3234
className={className}
3335
variant={variant}
3436
onClick={onClickWithSpinner}
35-
loading={isSaving}
37+
loading={processing}
3638
size={size}
3739
icon={icon}
3840
>

0 commit comments

Comments
 (0)