From 6b92bceaa32cd7e26fd303d1778afd395c553cda Mon Sep 17 00:00:00 2001 From: sangminnn Date: Wed, 25 Sep 2024 23:11:11 +0900 Subject: [PATCH] =?UTF-8?q?fix(react):=20useBlockPromiseMultipleClick=20?= =?UTF-8?q?=ED=9B=85=20=EC=82=AC=EC=9A=A9=20=EC=8B=9C=20Error=20=EC=83=81?= =?UTF-8?q?=ED=99=A9=EC=97=90=EC=84=9C=20isLoading=EA=B0=92=EC=9D=B4=20?= =?UTF-8?q?=EB=B0=94=EB=80=8C=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../useBlockPromiseMultipleClick/index.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/react/src/hooks/useBlockPromiseMultipleClick/index.ts b/packages/react/src/hooks/useBlockPromiseMultipleClick/index.ts index 68bcdec31..0890d3bdf 100644 --- a/packages/react/src/hooks/useBlockPromiseMultipleClick/index.ts +++ b/packages/react/src/hooks/useBlockPromiseMultipleClick/index.ts @@ -1,22 +1,28 @@ -import { useRef, useState } from 'react'; +import { useCallback, useRef, useState } from 'react'; export function useBlockPromiseMultipleClick() { const [isLoading, setIsLoading] = useState(false); const isClicked = useRef(false); - const blockMultipleClick = async (callback: () => Promise) => { - if (isClicked.current) { - return; - } + const blockMultipleClick = useCallback( + async (callback: () => Promise) => { + if (isClicked.current) { + return; + } - isClicked.current = true; - setIsLoading(true); + isClicked.current = true; + setIsLoading(true); - await callback(); - - isClicked.current = false; - setIsLoading(false); - }; + try { + const result = await callback(); + return result; + } finally { + isClicked.current = false; + setIsLoading(false); + } + }, + [], + ); return { isLoading,