codestates / codestates/BanThing

[Error Handling] useEffect 와 상태 관리 함수

Open
#171 0 comments 0 reactions 1 assignee Claimed by @tmdqls2257 View on GitHub
client error solved
Dominant language
TypeScript
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### 어떤 에러인가요?
![image](https://user-images.githubusercontent.com/54207332/155527456-1c76f3cd-a172-48ff-b538-701f84c9c078.png)

- 에러 메시지
```
next-dev.js?3515:32 Warning: Cannot update a component (`Sidebar`) while rendering a different component (`JoinRoom`). To locate the bad setState() call inside `JoinRoom`, follow the stack trace as described in
```

### 에러 핸들링 방법
- useEffect 밖에서 상태 함수를 업데이트 해주면서 생기는 오류 이다.
-
```
useEffect(() => {
const getPosts = async () => {
try {
if (roomsId !== 0) {
axios
.post(`${process.env.NEXT_PUBLIC_SERVER_ENDPOINT}/main`, {
id: roomsId,
})
.then((response) => {
setData(response.data);
});
}
} catch (e) {
console.log(e);
}
};
getPosts();
if (chats) {
setUsersChats(chats);
}

if (data) {
setroomTitle(data.data.post.title);
}
}, [roomsId]);
```

### 에러 핸들링을 위해 참고한 레퍼런스 링크
- Memory-It 의 Error Handling 예시입니다.
[링크](https://github.com/codestates/Memory-It/issues/205)

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.