-
Notifications
You must be signed in to change notification settings - Fork 17
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] local storage의 CurrentFloor 값이 없을 때 발생하는 TypeError 에러 수정 #1727 #1728
base: dev
Are you sure you want to change the base?
[FE] local storage의 CurrentFloor 값이 없을 때 발생하는 TypeError 에러 수정 #1727 #1728
Conversation
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.
고생하셨습니다~
frontend/src/Cabinet/components/SectionPagination/SectionPagination.container.tsx
Outdated
Show resolved
Hide resolved
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.
요즘 센트리 알림이 계속 왔었는데 이 이유 때문이었군요! 상세한 설명 감사합니다!!
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.
저번에 해당 에러를 어떻게 처리하면 좋을지 같이 구두로 이야기 나눠보았던것 같은데 잘 마무리 지으셨군요! 센트리 알림이 종종 오길래 신경쓰였는데 해결되어 다행입니다. 고생 많으셨습니당👍👍
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.
센트리를 이용해 이런식으로 에러 추적을 하는군요.. 많이 배워갑니다! 변수명 통일하는 부분도 잘 숙지하도록 하겠습니다 pr을 상세히 적어주신 덕분에 아직 잘 모르는 부분들도 이해가 훨씬 수월했습니다! 고생 많으셨어요!
TypeScript의 타입 체크는 컴파일 타임에만 동작하고 런타임에서는 사라지기 때문에, 실제 실행 중에 값이 undefined인지 확인해야하는 경우가 있어요. currentFloor에 대한 런타임 체크가 존재하지 않아서 undefined인 경우에 toString메서드를 실행하려고 해서 문제가 발생했던 것 같습니다. 추가적으로 궁금한 부분이 있는데 에러 발생 시 메인 페이지로 보내는 것은 어디서 처리되는건가요? 생각보다 찾기가 힘드네요. |
트러블 슈팅 문서 - 초깃값 변경 고민에 작성했듯이 undefined로 유지할까도 생각했는데요, |
메인 페이지로 보내는 등의 처리는 따로 안했고, 에러가 발생하면 센트리가 자동으로 에러가 발생한 경로 및 파일 등을 수집해서 기록합니다. |
해당 사항 (중복 선택)
설명
더 자세한 내용은 트러블 슈팅 문서를 참고하세요
문제
before.mov
센트리를 통해
currentFloor
가undefined
일때toString
을 호출 시 발생하는 에러임을 확인.atom 정의부 확인하니 초기값이 undefined로 설정돼있음.
원인
로컬스토리지에 currentFloor 값이 없는채로 페이지를 새로고침하면 recoil의 상태도 함께 초기화됨. 따라서 currentFloor는 undefined(초기값)가 됨.
해결
초기값을 0으로 변경
after.mov
로컬스토리지에 값 없을 시 /home으로 이동
리팩토링
currentFloorNumberState
변수명 통일현재 currentFloorNumberState를 여러 파일에서 currentFloorNumber, currentFloor, floor 같이 다양하게 선언해서 사용 중.
이렇게 같은 state를 다른 변수명으로 사용 시 단점
대표적으로 위와 같은 단점이 있기에 효율을 높이고 실수를 방지하기 위해 변수명을 currentFloor로 통일하게 됨.
useRecoilState
vsuseRecoilValue
- value 밖에 안쓰면 useRecoilValue로 변경미미하지만 유효한 차이가 있기 때문에, currentFloor를 선언할 때 value만 사용하는 경우에는 useRecoilState 대신 useRecoilValue로 변경함.
이 외의 코드 변경
0으로 초기화한 후 새로고침 했을때 /home으로 이동하기 전에 MainPage 컴포넌트가 잠깐 보이는 이슈 발생
해결 : 삼항 연산자를 사용하여 로딩 끝난 후 currentFloor 없으면 바로 홈페이지로 이동되도록 로직 수정
👉🏻 currentFloor가 undefined가 되는 추가적인 경우가 있다면 알려주세요 👈🏻
그리고 더 좋은 해결 방법이나 의견 있으면 편하게 코멘트 달아주세요 !
#1727