
// GroupApplyModal.tsx
const throttleRef = useRef(false);
const addGroupApplyHandler = useCallback(async () => {
if (throttleRef.current) return;
throttleRef.current = true;
setTimeout(() => {
throttleRef.current = false;
}, 5000);
}, [
id,
name,
phone,
address,
detailAddress,
checkBox,
user,
addMutation,
addAlarm,
]);
먼저 throttleRef라는 ref를 제작하고, addGroupApplyHandler 함수를 useCallback으로 변경한 후 throttleRef.current가 true일 경우 바로 return하여 코드가 실행되지 않게 했다. false일 경우에는 true로 변경시킨 후 모든 코드를 실행하고, setTimeout으로 5초 후에 다시 throttleRef.current를 false로 적용했다.