-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 방 생성 및 방 참여 API 호출에 쓰로틀링을 걸어 중복 호출 방지 #401
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useRef } from 'react'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const useThrottle = (func: (...args: any[]) => void, delay = 1000) => { | ||
const isThrottle = useRef(false); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return (...args: any[]) => { | ||
if (!isThrottle.current) { | ||
func(...args); | ||
isThrottle.current = true; | ||
setTimeout(() => { | ||
isThrottle.current = false; | ||
}, delay); | ||
} | ||
}; | ||
}; | ||
|
||
export default useThrottle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters