Skip to content

Conversation

@jaeyoung-kwon
Copy link
Member

#️⃣ 연관된 이슈

ex) #이슈번호, #이슈번호
#111

📝 훅 간단 사용 설명

어떤 훅인지 간단하게 설명해주세요! (docs 내용 기반)

useGeolocation은 브라우저의 Geolocation API를 사용하여 사용자의 현재 위치를 가져오거나 추적(watch) 하는 커스텀 React 훅입니다.

위도(latitude), 경도(longitude) 등 좌표 정보를 손쉽게 얻을 수 있으며,
옵션에 따라 한 번만 위치를 가져오거나(getCurrentPosition), 지속적으로 위치를 추적(watchPosition) 할 수 있습니다.

스크린샷 (선택)

Screen.Recording.2025-09-29.at.12.28.46.PM.mov

@vercel
Copy link

vercel bot commented Sep 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
2025-fe-hookdle-docs Ready Ready Preview Comment Oct 5, 2025 8:30am

@github-actions
Copy link

github-actions bot commented Sep 29, 2025

🚀 테스트 결과

실행 시간: 2025년 10월 05일 17시 31분 37초
커밋: 696423f

📊 요약

  • Lint: ✅ 성공
  • Tests: ✅ 성공

📝 Lint Check

✅ Lint check passed

🧪 Tests

✅ Tests passed

Copy link
Collaborator

@jeongyou jeongyou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구현해주신 코드 잘 보았습니다! 전체적으로 훅의 동작 흐름이 잘 잡혀 있어서 읽는 데 큰 어려움이 없었습니다 👍
간단한 궁금증과 제 생각도 코멘트로 남겨두었습니다. 확인해주시면 감사하겠습니다!

Comment on lines 65 to 67
if (!('geolocation' in navigator) || !navigator.geolocation) {
setError({ code: 0, message: 'Geolocation is not supported by this browser.' } as GeolocationPositionError);
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

브라우저 미지원 처리를 error에 넣는 대신, isSupported 같은 별도 상태로 분리하면 어떨까요?
권한 거부나 타임아웃처럼 실패 상황과는 성격이 다른 것 같아서 이렇게 분리하면 UI 분기할 때 더 명확해질 것 같습니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 그렇네요! 상태 분리하는 거 좋은 것 같습니다!! 👍

refactor: API 지원여부 상태 추가

}: 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]);
Copy link
Collaborator

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 측면에서 오히려 불필요할 수 있겠다는 생각도 드네요...!

혹시 처음 한 번만 로딩을 보여주고 이후에는 값만 갱신하기 위한 용도였을까요...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 꼼꼼한 리뷰 감사합니다! 기린 말대로

refactor: 옵션이 변경될 때마다 로딩 값 업데이트 해주기

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants