codestates / codestates/BookDam

22.01.12 Error Handling

Open
#138 0 comments 0 reactions 0 assignees View on GitHub
Complete
Dominant language
JavaScript
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

> 해결된 에러라면 라벨에 'Complete' 를 달아주세요.
> 미해결된 에러라면 라벨을 'In progress' 로 변경해주세요.

### 어떤 에러인가요?
- Feedpage에서 해당 유저의 아이콘을 클릭하면 해당 유저의 정보를 볼 수 있는 userpage/해당 유저아이디를 주소로 하는 페이지로 이동
- 그런데 상태 변경을 해주어도 전달되는 followInfo가 변경되지 않는 상태로 전달되고 있음

### 에러 메시지

```js
const getFollowInfo = (el) => {
console.log(el.id, el.userNickName)
setFollowInfo({
id: el.id,
userId: el.userId,
userNickName: el.userNickName,
userImage: el.userImage
})

console.log("팔로우 유저정보",followInfo)
history.push({
pathname: `/userPage/${followInfo.userNickName}`,
state: { followInfo: followInfo }})
}
```
getFollowInfo 함수가 모두 실행되고 해당 페이지 리랜더링 되어야
 상태함수 변경된게 최종적으로 적용되는데

리랜더링 완료되기 전에
 history.push로 페이지 이동하면서 전달해주니
빈값만 전달되고 있는 상황.

팀원 4명이 모두 붙어서 3시간을 붙었으나 해결이 되지 않았음.

### 에러 핸들링 방법

- 해결책은 간단함. 상태변경 안시키고 그냥 변경된 값 자체를
전달시켜주었음

```js
const getFollowInfo = (el) => {
console.log(el.id, el.userNickName)
setFollowInfo({
id: el.id,
userId: el.userId,
userNickName: el.userNickName,
userImage: el.userImage
})

history.push({
pathname: `/userPage/${el.userNickName}`,
state: { followInfo: {
id: el.id,
userId: el.userId,
userNickName: el.userNickName,
userImage: el.userImage
} }})
}
```
리액트 상태변경은 고정관념이다.

페이지 리랜더링 되기 전에 그냥 던져줘야 하는 상황도 있다.

### 에러 핸들링을 위해 참고한 레퍼런스 링크

[링크]()

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.