-
Notifications
You must be signed in to change notification settings - Fork 2
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
[FE] 존재하지 않는 element에 대한 에러를 출력하는 유틸리티 함수 제작 #150
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ee32af
feat: 존재하지 않는 element에 대한 에러를 출력하는 훅 제작
ImxYJL 3be25ea
chore: hooks 폴더 index에 useExistentElement 추가
ImxYJL 89871ec
refactor: useExistentElement 훅을 더욱 범용적으로 사용할 수 있도록 수정
ImxYJL bda34f7
refactor: 존재하지 않는 요소를 판별하는 동작을 커스텀 훅 대신 유틸리티 함수로 제작
ImxYJL c2970e7
chore: 기존의 존재하지 않는 요소를 탐지하는 커스텀 훅 삭제
ImxYJL 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './date'; | ||
export * from './isExistentElement'; |
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,18 @@ | ||
type NullableElement = Element | HTMLElement | null | undefined; | ||
|
||
export const isExistentElement = (element: NullableElement, elementName: string): boolean => { | ||
const isExistentElement = element !== null && element !== undefined; | ||
const isHTMLElementOrElement = element instanceof HTMLElement || element instanceof Element; | ||
|
||
if (!isExistentElement) { | ||
console.error(`${elementName}을/를 찾을 수 없습니다.`); | ||
return false; | ||
} | ||
|
||
if (!isHTMLElementOrElement) { | ||
console.error(`${elementName}은/는 Element 이하의 타입이 아닙니다.`); | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
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.
존재 여부 뿐만 아니라
Element
이하 타입도 확인해줘서 좀 더 구체적으로 검증하는 것 같아서 좋은 것 같아요!