-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] - 삭제 및 등록 시 여러번 요청하지 못하게 수정 #295
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59ba431
feat(useLeadingDebounce): 선행 디바운드 훅 구현
simorimi 6e0b374
fix: 삭제 반복 요청하지 않도록 수정
simorimi 091a9e2
fix: 등록 반복 요청하지 않도록 수정
simorimi 691ab75
refactor(useLeadingDebounce): 렌더링과 무관하기에 useState 에서 useRef로 수정
simorimi baa3a03
Merge branch 'develop/fe' of https://github.com/woowacourse-teams/202…
simorimi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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 { useState } from "react"; | ||
|
||
const useLeadingDebounce = (callback: () => void, delay: number) => { | ||
const [isDebouncing, setIsDebouncing] = useState(false); | ||
|
||
const debouncedCallback = () => { | ||
if (!isDebouncing) { | ||
callback(); | ||
setIsDebouncing(true); | ||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setTimeout이 있다면 clearTimeout이 있어야 메모리 누수를 막을 수 있다고 하네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 피드백입니다! 해당 부분 반영했습니다! |
||
setIsDebouncing(false); | ||
}, delay); | ||
} | ||
}; | ||
|
||
return debouncedCallback; | ||
}; | ||
|
||
export default useLeadingDebounce; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 상태는 ui 상태에 영향을 주는건 아니니 �hook이 아닌 함수로 사용할 수 있지 않을까 싶어요!
https://github.com/toss/es-toolkit/blob/main/src/function/debounce.ts 참고 링크 드립니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useRef로 변경해보았습니다! 렌더링 주기를 고려하는 것이 예를 들어, unmount 될 때 cleartimeout을 하는 것이 좋을 것 같아서 변경해보았습니다! 확인 바랍니다