-
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 1 commit
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useEffect, RefObject } from 'react'; | ||
|
||
const useExistentElement = <T extends HTMLElement>(ref: RefObject<T>, elementName: string) => { | ||
useEffect(() => { | ||
if (!ref.current) { | ||
console.error(`${elementName}을/를 찾을 수 없습니다.`); | ||
} | ||
}, [ref, elementName]); | ||
}; | ||
|
||
export default useExistentElement; |
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.
사용범위를 더 넓여보는 것은 어떨까요?
위 코드는 ref.current의 존재 여부를 확인하는 기능이네요
ref가 아닌
const element =document.querySelector('#contents')
인 element에는 적용할 수 없어요ref보다는 HTMLElement|Element|null|undefined 인 요소를 훅의 props로 받고 HTMLElement,Element 인지를 판단한다면
사용범위가 넓어질 것 같아요
props 타입에 대한 컨벤션
프론트 코드 컨벤션이 훅/컴포넌트 외부에서 props타입을 선언하기로 했어요. props 타입을 훅 외부로 빼고 제너릭을 사용할 수 있도록 수정해보는 것은 어떨까요?