-
Notifications
You must be signed in to change notification settings - Fork 0
useGeolocation 훅 #123
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
base: dev
Are you sure you want to change the base?
useGeolocation 훅 #123
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🚀 테스트 결과실행 시간: 2025년 10월 05일 17시 31분 37초 📊 요약
📝 Lint Check✅ Lint check passed 🧪 Tests✅ Tests passed |
jeongyou
left a comment
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.
구현해주신 코드 잘 보았습니다! 전체적으로 훅의 동작 흐름이 잘 잡혀 있어서 읽는 데 큰 어려움이 없었습니다 👍
간단한 궁금증과 제 생각도 코멘트로 남겨두었습니다. 확인해주시면 감사하겠습니다!
| if (!('geolocation' in navigator) || !navigator.geolocation) { | ||
| setError({ code: 0, message: 'Geolocation is not supported by this browser.' } as GeolocationPositionError); | ||
| return; |
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.
브라우저 미지원 처리를 error에 넣는 대신, isSupported 같은 별도 상태로 분리하면 어떨까요?
권한 거부나 타임아웃처럼 실패 상황과는 성격이 다른 것 같아서 이렇게 분리하면 UI 분기할 때 더 명확해질 것 같습니다!
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.
오 그렇네요! 상태 분리하는 거 좋은 것 같습니다!! 👍
| }: UseGeolocationOptions = {}): UseGeolocationReturns { | ||
| const [coords, setCoords] = useState<GeolocationCoordinates | null>(null); | ||
| const [error, setError] = useState<GeolocationPositionError | null>(null); | ||
| const loading = useMemo(() => coords === null && error === null, [coords, error]); |
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.
이 부분 useMemo에서 coords와 error를 의존성으로 두고 있는데, 제 생각에는 옵션이 변경되어 useEffect 내에서 새로 위치 요청을 보내더라도 기존의 coords나 error 값이 남아 있으면 loading 값이 갱신되지 않을 것 같습니다!
이펙트 시작할 때 coords와 error를 초기화하여 재요청 동안 loading = true가 되도록 하는 방법도 고려해볼 수 있을 것 같습니다!
그런데 watch 모드처럼 지속적으로 위치가 바뀌는 상황에서는 매번 로딩이 켜졌다 꺼지는 게 UX 측면에서 오히려 불필요할 수 있겠다는 생각도 드네요...!
혹시 처음 한 번만 로딩을 보여주고 이후에는 값만 갱신하기 위한 용도였을까요...?
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.
오 꼼꼼한 리뷰 감사합니다! 기린 말대로
#️⃣ 연관된 이슈
📝 훅 간단 사용 설명
useGeolocation은 브라우저의 Geolocation API를 사용하여 사용자의 현재 위치를 가져오거나 추적(watch) 하는 커스텀 React 훅입니다.위도(
latitude), 경도(longitude) 등 좌표 정보를 손쉽게 얻을 수 있으며,옵션에 따라 한 번만 위치를 가져오거나(
getCurrentPosition), 지속적으로 위치를 추적(watchPosition) 할 수 있습니다.스크린샷 (선택)
Screen.Recording.2025-09-29.at.12.28.46.PM.mov