codestates / codestates/HoloSulo
[Error-Handling] 성재호 2022-03-03
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?
useEffect 관련 렌더링 문제 (page가 로드 되기전에 렌더 되지 않음)
- userInfo 조회 시 data 조회전 페이지 로드
원인은 API 통신은 비동기로 처리 되기 때문임
### 에러 메시지
```shell
$ Uncaught TypeError: Cannot read properties of undefined ( reading 'totalHour' )
```
### 에러 핸들링 방법
> 문제가 되는 부분에 ?(안전) 연산자를 이용함 으로 페이지가 실제로 사용할 수 있기 전까지
> 검색을 하지 않도록 하며 경우에 따라 훨씬 더 문제가 되는 시나리오 방지
> 즉, 페이지 로드 후 데이터를 통신하기 전 까지 오류 발생을 시키지 않게끔 함
```js
{user.data.totalHour}
// ? 연산자 data 뒤 삽입
{user.data?.totalHour}
```
### 에러 핸들링을 위해 참고한 레퍼런스 링크
- https://stackoverflow.com/questions/45422908/cannot-read-property-title-of-undefined-but-title-is-displayed
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.